TypeScript Version: 2.1.4
Compiled with --target ES5.
Code
// A *self-contained* demonstration of the problem follows...classMain{constructor(){this.register("a","b","c");}privateregister(...names: string[]): void{for(letnameofnames){console.log(name);this.bar({[name+".a"]: ()=>{this.foo(name);},});}}privatebar(a: any): void{}privatefoo(name: string): void{}}newMain();Expected behavior:
Code prints "a", "b", and "c" on three lines
Actual behavior:
Code prints only a single line containing "a".
The bug only occurs when using both a Rest parameter ("...names") and the computed property name ([name + ".a"]) and a for-of loop and the arrow function in the loop body.
When I look at the generated JS I can see that there is a clash in variable declaration in the for-loop and the loop-body that has been extracted into a function.
TypeScript 2.1.5 gives correct output, but I have not found any explicit bug that is supposed to fix this behavior. So I am afraid that it was fixed only as a side effect of some other change and might break again in the future.
Could you include a test case like this?
TypeScript Version: 2.1.4
Compiled with --target ES5.
Code
Expected behavior:
Code prints "a", "b", and "c" on three lines
Actual behavior:
Code prints only a single line containing "a".
The bug only occurs when using both a Rest parameter ("...names") and the computed property name ([name + ".a"]) and a for-of loop and the arrow function in the loop body.
When I look at the generated JS I can see that there is a clash in variable declaration in the for-loop and the loop-body that has been extracted into a function.
TypeScript 2.1.5 gives correct output, but I have not found any explicit bug that is supposed to fix this behavior. So I am afraid that it was fixed only as a side effect of some other change and might break again in the future.
Could you include a test case like this?