2017-10-06T00:40:10Z||2017-10-06T00:40:10Z


Like many other languages, TypeScript allows variable shadowing. For example, this code compiles fine as the value variable in forEach actually shadows the value variable declared in outer scope.

function test(value: number) {
  [1, 2, 3].forEach((value) => {
    console.log(value);
  });
}

test(1000);

I think this may trigger unexpected problems if programmers are not aware of the shadowing. Luckily, TSLint can detect this easily, emitting an error:

[tslint] Shadowed name: 'value' (no-shadowed-variable)