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
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:
TypeScript Version: 3.7.2
Search Terms: inline, generic type, conditional type, Extract
Code
Expected behavior: All assignments typecheck
Actual behavior: Assignments with inlined conditional type all report type error
Playground Link
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:
keyof "a"
behaves differently when using a type parameter #23345 (comment)The text was updated successfully, but these errors were encountered: