Closed
Description
Bug Report
π Search Terms
switch incorrectly narrows type
π Version & Regression Information
v4.3.5
β― Playground Link
Playground link with relevant code
π» Code
const symbol = Symbol("Test");
function f(x: 1 | "a" | typeof symbol | {} | (() => void)): void {
switch (typeof x) {
case "number":
case "object":
case "string":
case "symbol":
}
switch (typeof x) {
case "function":
case "object":
case "string":
case "symbol":
}
switch (typeof x) {
case "function":
case "number":
case "string":
case "symbol":
}
switch (typeof x) {
case "function":
case "number":
case "object":
case "symbol":
}
switch (typeof x) {
case "function":
case "number":
case "object":
case "string":
}
switch (typeof x) {
case "function":
case "number":
case "object":
case "string":
case "symbol":
}
}
π Actual behavior
Starting from 4th switch the type of x is narrowed to {}.
π Expected behavior
The type of x should not be narrowed