title: Typescript: Generic type of function parameter signature
body: <p>I try to declare a type which defines a transformation of a function type generating a type with the same arguments but another return type.<br>
  The goal is to write a function <code>createAction</code> which expects a function and returns a new function expecting the same arguments as the given one but returning another type.</p>
  
  <p>Input: function expecting a string and a number, returning type <code>R</code>:</p>
  
  <pre><code>const fn = (s: string, n: number) =&gt; ({ s, n, b: false })
  const g = createAction(fn)
  </code></pre>
  
  <p>Expected type of <code>g</code> is:
  function expecting a string and a number, returning type <code>{ payload: R }</code>:</p>
  
  <pre><code>typeof g === (s: string, n: number) =&gt; ({ payload: { s: string, n: number, b: boolean } })
  </code></pre>
  
  <p>This would allow me to write another function <code>createActions</code> expecting a function map and returning the same map but with transformed functions:</p>
  
  <pre><code>const t = createActions({
      func1: (s: string) =&gt; ({}),
      func2: (n: number, b: boolean) =&gt; ({ n }),
  });
  typeof t === {
      func1: (s: string) =&gt; ({ payload: {} }),
      func2: (n: number, b: boolean) =&gt; ({ payload: { n: number } }),
  }
  </code></pre>
  
  <p>I could create a type overload with different number of generic arguments to cover a number of different function signatures (see below) but I am looking for a more generic solution which allows inferring the parameter number and types of the given function automatically. Using type overloads makes the function map described above impossible to implement.</p>
  
  <p>A basic solution using generics by hard-coding the number of arguments:</p>
  
  <pre><code>type Transform&lt;D, T1, R&gt; = {
      [K in keyof D]: (p1: T1) =&gt; ({
          payload: R;
      });
  }
  interface CreateActions&lt;D, T1, R&gt; {
      (def: D): Transformed&lt;D, T1, R&gt;;
  }
  </code></pre>
  
  <p>Thanks for the help!</p>