Closed
Description
π Search Terms
type, scoping, ifStatement
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about type scoping
β― Playground Link
π» Code
function f1() {
if (true)
type s = string;
console.log("" as s);
}
function f2() {
if (true) {
type s = string;
}
console.log("" as s);
}
π Actual behavior
From type-system perspective in the first if
it appear that the console.log
is part of the body of the if
because the type is in scope. However the JS emit is:
function f1() {
if (true)
;
console.log("");
}
So the console.log
is not part of the if body.
π Expected behavior
function f1() {
if (true)
type s = string;
// @ts-expect-error : "cannot find name 's'"
console.log("" as s);
}
Also happy for this to be a parse error. An if statement with only a type declaration as a body hopefully has no use cases.
Additional information about the issue
No response