Microsoft/TypeScript
GitHub ã§èŠãUsing declarations like a statement leads to strange bugs.
Open
#62,896 opened on 2025幎12æ14æ¥
BugDomain: check: Control FlowFix AvailableHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð Search Terms
function declaration statement
ð Version & Regression Information
v 5.9.3
⯠Playground Link
ð» Code
if (true) var x = 0;
console.log(x); //ok
for (let i = 0; i < 3; i++) var j = i;
console.log(j) //error in compile: j is used before being assign, no error in runtime
if (true) function f() {}
f()//no error in compile time, but error in runtime: In strict mode code, functions can only be declared at top level or inside a block
ð Actual behavior
ð Expected behavior
Additional information about the issue
The questions above was raised only in academic purpose. I understand that there are no real use cases to apply code above.