-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Allow defining global to avoid 'FOO is not defined' warnings #7240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Another alternative would be to use the |
Thanks, I did stumble across Edit: this also came up before in the rollup plugin repo sveltejs/rollup-plugin-svelte#179 |
#7786 registered all global objects / functions. |
@baseballyama this issue is about defining my own globals (equivalent to the eslint |
Ahh 😩😩😩 |
Does this issue address existing type declaration files not being used? E.g. if I have a /**
* If this is a debug build.
* Constant is defined in `vite.config.js` and is replaced everywhere automatically.
*/
declare const DEBUG: boolean; Interestingly the language tooling picks up on it, but you still get the warning: |
I am also experiencing this false positive warning. This variable is declared in // vite-env.d.ts
declare var PageHash: {
SignUp: 'signup';
Login: 'login';
};
// main.ts
globalThis.PageHash = {
SignUp: 'signup',
Login: 'login',
}; The language server complains but the compiler is still able to pick up the global variable. Oh well, the language server is good if I explicitly access |
Part of me wonders if we still need this warning at all in 2023. TypeScript/typed JavaScript is ubiquitous at this point, which does a much better job at knowing which globals exist. |
We got rid of this warning in Svelte 5 for that exact reason, so I'll close this |
Describe the problem
I'm injecting globals using esbuild (https://esbuild.github.io/api/#define) and am flooded with warnings.
Describe the proposed solution
Allow configuring globals in addition to the hard coded list
svelte/src/compiler/compile/Component.ts
Line 1445 in 5665f71
I'm already defining them in my eslint
globals
config but it appears there is no such things for Svelte?Alternatives considered
<!-- svelte-ignore missing-declaration -->
all over the place. Depending on how fine grained I (can) do this it might mask legit warnings (the comment applies to the entire element and subtree, while I only want a specific thing to be known)MY_GLOBAL
I could hack around and usewindow.MY_GLOBAL
. This gets rid of the warning but introduces a new problem: if esbuild fails to replace this would leave the literalwindow.MY_GLOBAL
in the code (which would be undefined).Importance
would make my life easier
The text was updated successfully, but these errors were encountered: