@typescript-eslint/no-shadow complains about shadowing a variable that is just being declared, while I think it should only bicker about variables that have already been declared:
- I set
'@typescript-eslint/no-shadow': 'error'in my eslint config. - I add the code
const person = persons.find((person) => person.id === 123);
It produces the error 'person' is already declared in the upper scope.
I think, I basically understand why that is: In javascript, person is in fact already declared inside the arrow function (in typescript it's type simply being any).
But I can't think of a use case in which accessing it from the inner scope is ever useful - is there one?
If not, shouldn't there be another eslint rule to prevent just that and an option for no-shadow to disable checking the variable that is being declared in the current statement?
Answering your question directly: this is exactly what the
ignoreOnInitializationoption does.The typescript-eslint rule is an extension on the ESLint rule. Per the typescript-eslint docs, it takes in all the options that the base ESLint rule does.
Generally speaking: if you're wondering whether an ESLint rule has a particular option, it's good to try reading the docs first. Each option in the rules -both in typescript-eslint and ESLint- are fully documented. You can try them in their projects' online playgrounds. This is a link to try the provided code snippet in the ESLint playground with
ignoreOnInitialization.