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
Conditional type *without union* behaves differently when inlined #36135
typeMyExtract<T,U>=TextendsU ? T : neverfunctionfoo<T>(a: T){constb: Extract<any[],T>=0asany;a=b;// okconstc: (any[]extendsT ? any[] : never)=0asany;a=c;// FAILS//^ Type 'any[] extends T ? any[] : never' is not assignable to type 'T'.// 'any[] extends T ? any[] : never' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.// Type 'any[]' is not assignable to type 'T'.// 'any[]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.(2322)constd: MyExtract<any[],T>=0asany;a=d;// oktypeCustomType=any[]extendsT ? any[] : never;conste: CustomType=0asany;a=e;// FAILS//^ Type 'CustomType' is not assignable to type 'T'.// 'CustomType' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.// Type 'any[]' is not assignable to type 'T'.// 'any[]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.(2322)}
Expected behavior: All assignments typecheck
Actual behavior: Assignments with inlined conditional type all report type error
Related Issues:
These are similar because they involve a generic type behaving differently when inlined, but they're because of the distributive property of conditional types and homomorphic mapped types, which doesn't apply to this issue:
Activity