title: Inferring function parameters in TypeScript
body: <p>I'm trying to make a type-safe map function (not the function below), but I'm stuck on getting the function parameters to infer correctly.</p>
  
  <pre><code>    export type Mapper&lt;U extends Unmapped&gt; = {
        mapped: Mapped&lt;U&gt;
      };
  
      export type Unmapped = {
        [name: string]: (...args: any[]) =&gt; any
      };
  
      export type Mapped&lt;U extends Unmapped&gt; = {
        [N in keyof U]: (...args: any[]) =&gt; Promise&lt;any&gt;
      };
  
      const map = &lt;U extends Unmapped&gt;(unmapped: U): Mapper&lt;U&gt; =&gt; ({
        mapped: Object.entries(unmapped).reduce(
          (previous, [key, value]) =&gt; ({
            ...previous,
            [key]: (...args: any[]) =&gt; new Promise((resolve) =&gt; resolve(value(...args)))
          }),
          {}
        ) as Mapped&lt;U&gt;
      });
  
      const mapped = map({ test: (test: number) =&gt; test });
  
      mapped.mapped.test('oh no');
  </code></pre>
  
  <p>Is it possible to let TypeScript infer them? Currently the functions inside the <code>mapped</code> object accept any parameters, but it should only take the parameters defined in the unmapped object. The function names do get inferred correctly.</p>