Description
Bug Report
π Search Terms
contextual, generic, inference, rest parameter, ts2345
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about generic inference
β― Playground Link
Playground link with relevant code
π» Code
function foo<A extends any[]>(
arg: <T extends { a: number }>(t: T, ...rest: A) => number
) { }
foo((t, u: number) => t.a)
/* Argument of type
'<T extends { a: number; }>(t: T, u: number) => number' is not assignable to parameter of type
'<T extends { a: number; }>(t: T, u: number) => number'.
π€π€π€
*/
π Actual behavior
The compiler infers that (t, u: number) => t.a
is of type <T extends {a: number}>(t: T, u: number) => number
, but then complains that this type is not assignable to itself (or at least an identically written type). The problem seems to be that the two generic T
's can't be unified for some reason.
π Expected behavior
The compiler should infer the function type as it's doing now, but without futher complaint.
Comes from this Stack Overflow question. I don't really quite get the use case; presumably a real world application would have more than one site where T
appears, like <T extends { a: number }>(t: T, ...rest: A) => T
, which has the same problem.
Is there an existing issue that mentions this? Is it intended? Limitation? Genuine bug?