The function signature for toHaveBeenCalledWith unfortunately breaks if a generic function that consists of overloads is passed. TypeScript is not able to infer the proper overload for functions through generics. Only a single overload signature is considered for parameter inferring. For example:
function hello(idx: number): void;
function hello(item: object): void;
function hello(arg: any): void { /* impl */}
// This won't work because `MatchableArgs` only infers `object` as parameter type.
expect(hello).toHaveBeenCalledWith(1);
This is a known limitation in TypeScript, but it feels inconvenient that workarounds are needed for function overloads. Overloads are not a rare concept seen in TypeScript projects. I'm wondering if it would make sense to go back to the non-inferred parameter types. i.e. simply using any[].
Authors: @zvirja @djungowski @kolodny
The function signature for
toHaveBeenCalledWithunfortunately breaks if a generic function that consists of overloads is passed. TypeScript is not able to infer the proper overload for functions through generics. Only a single overload signature is considered for parameter inferring. For example:This is a known limitation in TypeScript, but it feels inconvenient that workarounds are needed for function overloads. Overloads are not a rare concept seen in TypeScript projects. I'm wondering if it would make sense to go back to the non-inferred parameter types. i.e. simply using
any[].Authors: @zvirja @djungowski @kolodny