Closed as not planned
Description
π Search Terms
when inferring a type for function calls TS is not behaving consistently for extended unions.
π Version & Regression Information
I checked TS 5.8.3 and TS 5.8.2
β― Playground Link
π» Code
const foo1 = (arg: any) => {}
const foo2 = <T>(arg: T) => {}
const bar1 = <T extends "a">(arg: T) =>{
console.log(arg)
switch(arg){
case("a"):
let f = arg; // here inferred type of f is T extends "a"
foo1(arg); // here inferred type of arg is extends "a"
foo2(arg); // here inferred type of arg is T extends "a"
}
}
const bar2 = <T extends "a" | "b">(arg: T) =>{
console.log(arg)
switch(arg){
case("a"):
let f = arg; // here inferred type of f is T extends "a" | "b"
foo1(arg); // here inferred type of arg is "a"
foo2(arg); // here inferred type of arg is T extends "a" | "b"
}
}
π Actual behavior
arg used as an argument for foo1 inside bar2 is inferred to be of type "a"
or
arg is ever inferred as T extends "a" | "b"
π Expected behavior
arg used as an argument for foo1 inside bar2 is inferred to be of type T extends "a" | "b"
or
arg is inferred as "a"
Additional information about the issue
No response