title: How to manually curry a function in TypeScript?
body: <p>I encountered a js lib which provided the external ts types. Assuming it's </p>
  
  <pre><code>interface ComplicatedFunction {
      (n: number, p: any): string,
      (s: string, p: any): number,
      (b: boolean, p: any): number,
  }
  
  declare const fn: ComplicatedFunction
  </code></pre>
  
  <p>I want to curry it:</p>
  
  <pre><code>import fn from 'fn'
  const curriedFn = (p1: ?) =&gt;
      (p2: any) =&gt;
          fn(p1, p2)
  </code></pre>
  
  <p>The question is what is how to fill the p1's type? (all strict checks on)</p>
  
  <p>I tried using generic to fix the types:</p>
  
  <pre><code>const curry2 = &lt;P1, P2, R&gt;(fn: (n: P1, m: P2) =&gt; R) =&gt;
      (n: P1) =&gt; (m: P2) =&gt; fn(n, m)
  
  const curriedFn = curry2(fn)
  </code></pre>
  
  <p>unfortunately, the <code>curriedFn</code> falls into signature <code>(b: boolean, p: any): number</code>. The other two function signatures are omitted by this way.</p>