-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[no-shadow] declaring a global causes no-shadow to error #2654
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
Are you saying that because it's a Could you please clarify? |
@bradzacher perhaps both, although I think the |
Because of limitations, a global you've defined in your config doesn't have the context about if it's a type or a value - so it's treated as both. This is done on purpose so users can define global types that work with Also side note that This is what's happening: rule reports here because You've got a global thing defined in your config. Because you've configured The analyser then proceeds to analyse your file. Because the "module" scope is a child of the "global" scope, the local variable Our extension rule probably could be modified to stop |
Thanks for the quick response! til |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hi everyone. |
Hey, I think I found what's either a bug or a confusing way that globals and ambient types are handled (potentially similarly to the
no-undef
issue mentioned in the FAQs).I'm currently migrating a large codebase to use TypeScript. We have a global
has()
function that we use to determine what environment we're in. It's handled by our build system, and is set as a read-only global in our existing ESLint config.When I try and declare an ambient type for this global, I've noticed that
@typescript-eslint/no-shadow
thinks that I'm shadowing it. Removingglobals: { has: false }
from the config fixes this problem. Is this expected behavior?Thanks in advance, and sorry if I'm overlooking something.
Repro
I set up a fresh project by running the following in an empty directory:
I then added these two files
Expected Result
I'd expect
yarn eslint index.d.ts
to not error.Actual Result
It logged the following error:
Versions
@typescript-eslint/eslint-plugin
4.4.0
@typescript-eslint/parser
4.4.0
TypeScript
4.0.3
ESLint
7.10.0
node
12.15.0
The text was updated successfully, but these errors were encountered: