0

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?

Page not found
  • 2,454
  • 2
  • 10
  • 19
  • 3
    Partial type inference is not supported yet. If you pass one type argument, you have to pass all of them. That's just how it is. To solve it, you can either *not* pass any type arguments, explicitly pass `T` as well, or use currying as [this](https://tsplay.dev/WYLoEm) playground shows. – kelsny Mar 19 '23 at 22:00
  • Looks more like an answer than a comment. Thank you!! – Page not found Mar 19 '23 at 22:02
  • Can the downvoter please elaborate? – Page not found Mar 19 '23 at 22:35
  • This question was closed as duplicate. I will leave it here as both question and answer (in comments) are much easier to understand. – Page not found Mar 20 '23 at 07:33

0 Answers0