-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[no-shadow] new false positive in 4.0.0 for function argument types #2447
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
Believe it or not, this isn't actually a false-positive. Each parameter in a function type declares a value variable so that you can reference it later within a So there is shadowing that occurs here. const obj = 1;
type Fn = (obj: string) => typeof obj;
declare const fn: Fn;
const result = fn(''); // what's the type of result? You might think that This is probably a rare case, so I could see value behind the addition of an option to ignore this? I guess it depends on how rare it actually is. |
Thanks for the great example, that made it clear (I'd link to that from the the no-shadow docs!). If I had to guess, though, I'd agree with you that defining a return type using |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…terNameValueShadow` Fixes #2447 Technically this is backwards incompatible, because I'm adding the option true by default, but I believe that the case it protects against is so rare that it's a substantially better experience this way, and it's what people expect
Repro
Note that
obj
is used both as the name of the first argument, and for typing the second argument. The second argument'sobj
is unused, sono-shadow
shouldn't have a problem with this, and indeed, this code when using theno-shadow
rule withpasses linting. But after upgrading to
I see
21:7 error 'obj' is already declared in the upper scope no-shadow
If I switch my .eslintrc.js to
I still see
error 'obj' is already declared in the upper scope @typescript-eslint/no-shadow
.Additional Info
Versions
@typescript-eslint/eslint-plugin
4.0.1
@typescript-eslint/parser
4.0.1
TypeScript
4.0.2
ESLint
7.7.0
node
14.5.0
The text was updated successfully, but these errors were encountered: