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
Compose function can not deduce generic types of arguments if compose function is defined right to left #31738
(11,3): error TS2345: Argument of type '<T extends any>(element: T) => T[]' is not assignable to parameter of type '(y: unknown) => T'.
Type 'unknown[]' is not assignable to type 'T'.
'unknown[]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'any'.
Expected behavior:
I expect doubleArray to be inferred as number[][]. Actual behavior:
It is inferred as unknown.
I'm also not sure how to help typescript, to infer this correctly, for example, this doesn't work:
I think this might be a design limitation. See this comment from the H-O inference PR: #30215
The above algorithm is not a complete unification algorithm and it is by no means perfect. In particular, it only delivers the desired outcome when types flow from left to right. However, this has always been the case for type argument inference in TypeScript, and it has the highly desired attribute of working well as code is being typed.
Activity
jack-williams commentedon Jun 3, 2019
I think this might be a design limitation. See this comment from the H-O inference PR: #30215