-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Closed as not planned
Closed as not planned
Copy link
Labels
7.0 LS MigrationBugA bug in TypeScriptA bug in TypeScriptDomain: LS: Quick Infoe.g. hover text, tool-tips, and tooltips.e.g. hover text, tool-tips, and tooltips.Help WantedYou can do thisYou can do this
Milestone
Description
Bug Report
π Search Terms
while switch union narrowing never
π Version & Regression Information
Version: 4.5.4
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about while, loop, switch
β― Playground Link
Playground link with relevant code
π» Code
let foo: "aaa" | "bbb" = "aaa";
while (true) {
switch (foo) {
case "aaa":
1+1; //any statement
break;
case "bbb":
1+1; //any statement
break;
}
if (foo === "aaa") {
console.log("Foo is aaa");
foo = "bbb";
} else if (foo === "bbb") { //says foo is never
console.log("Foo is bbb");
console.log("Loop is done");
break;
}
}π Actual behavior
On the line } else if (foo === "bbb") { when you hover over foo typescript thinks the type is never. If that was the case then you'd expect nothing inside that block to run.
π Expected behavior
foo should be type "bbb" here, and if you remove the switch statement it is. Furthermore if you run the compiled JS, it does hit all the console.log lines and produces
Foo is aaa
Foo is bbb
Loop is done
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
7.0 LS MigrationBugA bug in TypeScriptA bug in TypeScriptDomain: LS: Quick Infoe.g. hover text, tool-tips, and tooltips.e.g. hover text, tool-tips, and tooltips.Help WantedYou can do thisYou can do this