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