You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constfoo1=(arg: any)=>{}constfoo2=<T>(arg: T)=>{}constbar1=<Textends"a">(arg: T)=>{console.log(arg)switch(arg){case("a"):
letf=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" }}constbar2=<Textends"a"|"b">(arg: T)=>{console.log(arg)switch(arg){case("a"):
letf=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
The text was updated successfully, but these errors were encountered:
π 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
https://www.typescriptlang.org/play/?jsx=0&ssl=22&ssc=2&pln=1&pc=1#code/MYewdgzgLgBAZiEBGGBeGAKAhgJwOYBcMWYAngJRoB8MA3gL4BQoksCIATGjADwAqVbPiJ9KqGg0bNw0GACNcKdPxgBTAB5RVYACYQYAIiwHBuQjFHVajGDBYQQAG1UA6RyDxC85GzAgB3AEsoYAALL3JrW1tgLAhVDCMDcgJfaJhnNm4zAG4YAHp8mFDVHFUYQLA4UrKdGChSAAdykDh4Cv0+NU1tPUNjGAAfQzkDNOj2JAi8wuLS8srqnFr6ppa2sw7urV19JKGRsfTbdg5pgqKSsoqqmtU6huaYVuJ8La6NHb794YNR3yYTGkrHkuC4yg+PV2-QMBz+Ji8IjEVCidhkTlc7k8Zh8tgCwTCEVRMTiCSSKXGtky7XQuQuc2uizuDzWzzabUCnW2vT2A1+-2O8EQUxxM0u8xuSxWj3WrzwWySlKFnHOsyuC1uy3uqyeL02nIs3OhP0OAMY9CAA
π» Code
π 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
The text was updated successfully, but these errors were encountered: