I have the following definition for a curried function in TypeScript:
interface Curried2<A, B, Z> {
(_0: A): (_0: B) => Z;
(_0: A, _1: B): Z;
}
I have the following function that should accept a function (curried or not):
function apply<T, U>(f: (_0: T) => U, x: T): U {
return f(x);
}
Now, given
let curried: Curried2<number, boolean, string> = ...
the following works (as expected):
apply<number, (_0: boolean) => string>(curried, 4);
But TypeScript cannot infer the type on its own:
apply(curried, 4);
(Even though there is only one overload for () which takes a single value.) It complains:
Argument of type 'Curried2<number, boolean, string>' is not assignable to parameter of type '(_0: number) => string' ...It has correctly inferred
T, but inferred U to be string. Why is this? What can I do to make type inference work for me in this case (as explicitly specifying T and U is too verbose for my taste)?
Thanks in advance!