The problem is best described in this playground:
function infer1<T>(arg: T) {
return arg;
}
infer1(123); // good: 123 = number ==> T number
function infer2<S, T>(arg: T) {
return arg;
}
infer2<string>(123); // bad: Expected 2 type arguments, but got 1.(2558)
Why isn't T
inferred when calling infer2
and how can this be fixed?