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 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. Removing globals: { 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 have read 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 -y
yarn add -D eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin
I then added these two files
// .eslintrc.js
module.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.ts
declare const has: (environment: "dev" | "prod" | "test") => boolean;
Expected Result
I'd expect yarn 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 |