You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
Even though the inner now variable is inside an inner scope where a variable of the same name resides, I don't believe that there is actually any shadowing.
Indeed the inner block cannot access the outer now variable. If we try (by commenting out line 3) then we get this tsc compile error:
error TS2448: Block-scoped variable 'now' used before its declaration
Code in the style above is pretty common IMHO and is readable, and should not trigger "no-shadowed-variable" (as I have shown there is technically no shadowing)
The text was updated successfully, but these errors were encountered:
You're right that it doesn't make much sense in your example.
As soon as you have a closure in your block, that a different story:
exportfunctionfoo(wam: boolean){if(wam){constnow=newDate();// if you remove this line, the next line will use `now` from the outer scopesetTimeout(()=>console.log(now));}constnow=newDate();setTimeout(()=>console.log(now));}
If there is enough demand from the community, we could add an option to ignore variables that are shadowed in their temporal dead zone, i.e. shadowed before the declaration.
I think, this is valid concern. Please add option that take temporal dead zone into account. We have such great keywords like let and const, but they are devalued by this rule.
If you remove that line, then the code won't pass tslint due to "no-use-before-declare"
Note that we don't really take this rule into account when making TSLint design decisions; it's not very useful with let / const syntax, it's slow to compute, and it's not enabled in the built-in configuration presets.
comment was
```
// To enable this, we need whitelist support and for this bug to be fixed: palantir/tslint#3078
```
remove it in order to have a valid JSON
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Bug Report
TypeScript code being linted
with
tslint.json
configuration:Actual behavior
Expected behavior
Even though the inner
now
variable is inside an inner scope where a variable of the same name resides, I don't believe that there is actually any shadowing.Indeed the inner block cannot access the outer
now
variable. If we try (by commenting out line 3) then we get this tsc compile error:Code in the style above is pretty common IMHO and is readable, and should not trigger "no-shadowed-variable" (as I have shown there is technically no shadowing)
The text was updated successfully, but these errors were encountered: