TypeScript Version: 3.2.0-dev.20181101
Search Terms:
Code
let baz = 2;
function foo(bar = () => baz) {
var baz = 1;
return bar();
}
Expected behavior:
No error.
baz in the initializer references the outer let baz = 2.
let baz = 1 is marked as unused.
Actual behavior:
Error Initializer of parameter 'bar' cannot reference identifier 'baz' declared after it.
At runtime: calling foo() returns 2, which shows that declarations in the function body are not in scope of parameter initializers.
Note that other parameters are in scope and can be used inside other parameters' initializer.
Playground Link: https://agentcooper.github.io/typescript-play/#code/DYUwLgBARghgXhAvBATAbgFADMCuA7AYzAEsB7PCLU0gClgCckIaBKJAPmnjYG8MIBEAG4xGsBMgCMmQRHrgc9Cg1aYAvkA
Related Issues:
#22769
/cc @Kingwl maybe you want to give this a shot as well (I hope this doesn't cause as much trouble as the last one 😆)
TypeScript Version: 3.2.0-dev.20181101
Search Terms:
Code
Expected behavior:
No error.
bazin the initializer references the outerlet baz = 2.let baz = 1is marked as unused.Actual behavior:
Error
Initializer of parameter 'bar' cannot reference identifier 'baz' declared after it.At runtime: calling
foo()returns2, which shows that declarations in the function body are not in scope of parameter initializers.Note that other parameters are in scope and can be used inside other parameters' initializer.
Playground Link: https://agentcooper.github.io/typescript-play/#code/DYUwLgBARghgXhAvBATAbgFADMCuA7AYzAEsB7PCLU0gClgCckIaBKJAPmnjYG8MIBEAG4xGsBMgCMmQRHrgc9Cg1aYAvkA
Related Issues:
#22769
/cc @Kingwl maybe you want to give this a shot as well (I hope this doesn't cause as much trouble as the last one 😆)