If we write ES6, shadowed vars should not be a problem (read es6-scoping). So the following:
const myVar = test;
class Test {
constructor(myVar) {}
}
// or
function (myVar) {}
// or
(myVar) => {}
Should not throw:
error (no-shadowed-variable) example.ts[x, y]: shadowed variable: 'myVar'
myVar is clearly shadowed in those examples, and the link you provided supports that. Not sure what the question is here? If you wish to allow variables in inner scopes to shadow identifiers that are already available in an enclosing scope, then simply turn off the no-shadowed-variable rule.
I was thinking that in these kind of cases when using let/const it should not complain about it. It should only complain when using var or when targeting ES5 or bellow. Maybe a es6 options or something. Is that something that you would consider adding?
The semantics still don't make sense to me -- the variable is quite literally shadowed. It is no more "safe" to shadow variables using let / const than it is with var.
That is true, it is literally shadowed. But is not unsafe though, I mean, all modern JS interpreters are able to figure out which variable to use depending on the scope it is in.
Anyway, I guess this doesn't make sense anyway.
Most helpful comment
That is true, it is literally shadowed. But is not unsafe though, I mean, all modern JS interpreters are able to figure out which variable to use depending on the scope it is in.
Anyway, I guess this doesn't make sense anyway.