Bug Report
🔎 Search Terms
switch while union never
🕗 Version & Regression Information
Playground link with relevant code
💻 Code
declare function isNever(n: never): boolean;
function f() {
let foo: "aaa" | "bbb" = "aaa";
while (true) {
switch (foo) {
case "aaa":
}
if (foo === "aaa") {
foo = "bbb";
} else if (isNever(foo)) { // incorrect OK
break;
}
}
}
🙁 Actual behavior
The code incorrectly checks as OK.
🙂 Expected behavior
The call to isNever should fail; on the second iteration of the loop isNever is invoked with "bbb"
Note that we don't see this behavior with the equivalent if:
declare function isNever(n: never): boolean;
function f() {
let foo: "aaa" | "bbb" = "aaa";
while (true) {
//switch (foo) {
// case "aaa":
//}
if (foo === "aaa") { }
if (foo === "aaa") {
foo = "bbb";
} else if (isNever(foo)) { // correct error
break;
}
}
}
See also #47538
Bug Report
🔎 Search Terms
switch while union never
🕗 Version & Regression Information
Playground link with relevant code
💻 Code
🙁 Actual behavior
The code incorrectly checks as OK.
🙂 Expected behavior
The call to
isNevershould fail; on the second iteration of the loopisNeveris invoked with"bbb"Note that we don't see this behavior with the equivalent
if:See also #47538