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
When comparing a generic type to a conditional type whose checkType is the same type, we have additional information that we are not utilizing.. for instance:
functionf<Textendsnumber>(x: T){vary: Textendsnumber ? number : string;// `T` is not assignable to `T extends number ? number : string`y=x;}
Ignoring intersections, we should be able to take the true branch all the time based on the constraint.
The intuition here is that T in the example above is really T extends number ? T : never which is assignable to T extends number ? number : string.
Similarly, with substitution types, we have additional information that we can leverage, e.g.:
declarefunctionisNumber(a: any): a is number;functionmap<Textendsnumber|string>(o: T,map: (value: Textendsnumber ? number : string)=>any): any{if(isNumber(o)){// `T & number` is not assignable to `T extends number ? number : string`returnmap(o);}}
When comparing a generic type to a conditional type whose checkType is the same type, we have additional information that we are not utilizing.. for instance:
Ignoring intersections, we should be able to take the true branch all the time based on the constraint.
The intuition here is that
Tin the example above is reallyT extends number ? T : neverwhich is assignable toT extends number ? number : string.Similarly, with substitution types, we have additional information that we can leverage, e.g.: