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
{{ message }}
Repository navigation
Unexpected Error for conditional type parameter if value is generic typed #50066
constdoSomething : <T>(input : (Textendsundefined ? never : T)|null)=>void=(input)=>{console.log(input);}/* The unexpected Error */constfunctionWithGenericType=<Textendsstring|null>(input : T)=>{doSomething(input);// Error: Type 'string' is not assignable to type 'T extends undefined ? never : T'.}/* Just some test to proove that the rest of my code is working as expected… */constgreeting : string|null=Math.random()>0.5 ? 'Hello' : null;doSomething(greeting);// No Error. As expected.
🙁 Actual behavior
An error appears when calling doSomething(input) from inside a function with generic typed input.
Resolving of conditional types involving unbound generic type arguments is deferred. At that point the compiler doesn't know what T extends undefined ? never : T resolves to, because the compiler doesn't know what type T is. Constraints are not taken into consideration. Same as #48243.
When actually calling the function the type argument is not unbound anymore, so the conditional type can be resolved.
Activity
MartinJohns commentedon Jul 27, 2022
Resolving of conditional types involving unbound generic type arguments is deferred. At that point the compiler doesn't know what
T extends undefined ? never : Tresolves to, because the compiler doesn't know what typeTis. Constraints are not taken into consideration. Same as #48243.When actually calling the function the type argument is not unbound anymore, so the conditional type can be resolved.
typescript-bot commentedon Jul 30, 2022
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.