Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
Hey, I think I found what's either a bug or a confusing way that globals and ambient types are handled (potentially similarly to theno-undef
issuementioned in the FAQs).
I'm currently migrating a large codebase to use TypeScript. We have a globalhas()
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.
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I haveread the FAQ and my problem is not listed.
Repro
I set up a fresh project by running the following in an empty directory:
yarn init -yyarn add -D eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin
I then added these two files
// .eslintrc.jsmodule.exports={root:true,parser:'@typescript-eslint/parser',plugins:['@typescript-eslint',],extends:['eslint:recommended','plugin:@typescript-eslint/recommended',],globals:{has:false,},rules:{"no-shadow":"off","@typescript-eslint/no-shadow":["error",{builtinGlobals:true}],}};
// index.d.tsdeclareconsthas:(environment:"dev"|"prod"|"test")=>boolean;
Expected Result
I'd expectyarn eslint index.d.ts
to not error.
Actual Result
It logged the following error:
1:15 error 'has' is already declared in the upper scope @typescript-eslint/no-shadow
Versions
package | version |
---|---|
@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 |