Closed
Description
typescript version: 1.7.5
I have the following code,
function testing () {
for (let i = 0; i < 5; i++) {
setTimeout(function () {
console.log(i);
},0);
}
}
when set the target javascript version to es5, ts compiler reports the following error:
Error:(7, 5) TS4091: Loop contains block-scoped variable 'i' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher.
but the compiled code is ok. and if I change the target javascript to es6, it won't have this error.
who can tell me why it give me the error? thanks!