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
This is a slightly more complicated version of #21756, and is still present after #21782. When a conditional type has a callable constituent, the types are not assignable to each other.
TypeScript $ node lib/tsc --noEmit test.ts
test.ts(11,35): error TS2322: Type 'F1<T>' is not assignable to type 'F2<T>'.
Type '0 | (() => 0)' is not assignable to type 'F2<T>'.
Type '0' is not assignable to type 'F2<T>'.
The text was updated successfully, but these errors were encountered:
Yeah, I think I have a similar issue in #21734 where generic constraints does not work well for anything but primary types.
This work as it should and throws an error because of the generic constraint
letfirst=<TextendsNumber>(items: Array<T>): T=>{returnitems.shift();}leta=first([1,2,3]);letb=first(["a","b","c"]);// error TS2345: Argument of type 'string[]' is not assignable to parameter of type 'Number[]'
This also works as it should, it inherits TType from the generic class
classItem<TType>{publicfirst<TextendsArray<TType>>(items: T){returnitems.slice(2,1).shift();}}letc=newItem<number>().first([1,2,3]);letd=newItem<number>().first(["a","b","c"]);//error TS2345: Argument of type 'string[]' is not assignable to parameter of type 'number[]'
But, whenever I use more complex structures as constraint it never fails
classCar{}lete=newItem<Car>().third([newCar(),newCar(),newCar()]);letf=newItem<Car>().third([1,2,3]);// no error because signature of third is third<number[]> instead of third<Car[]>
The issue here is that the signature for e line is Item<Car>.third<Car[]>and for f line is Item<Car>.third<number[]>, the type TType is never assigned down to method first
This is a slightly more complicated version of #21756, and is still present after #21782. When a conditional type has a callable constituent, the types are not assignable to each other.
TypeScript Version: 2.8.0-dev.20180208 (latest master)
Code
Expected behavior:
no errors
Actual behavior:
The text was updated successfully, but these errors were encountered: