title: How to properly type a wrapper function for methods of an object?
body: <p>I have an object that has multiple methods, each with different parameters and I am trying to define a wrapper function that will accept a method from this object and return a function with the same signature.</p>
  <p><a href="https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgLYE8BiBXECzAD2IAzgN4BQy1yxEAXMgBQCUyAvAHzIjaoBG0ANxUaYAO6FGrDt14Dho6hAQALKcxJgojLVFABzNl2R7DIgL4UKCYlrRZc+IqUYYceAnY7JKNWiAMzMbcAIwANErIEhoyJgBMkf4q6tJ6utqGIabaFFY2dmDI4lBwAA5l0D4APAAqyBAAHpAgACYkyADWEOiEMA4eznbcTFEwTm6Oni4kANq1ALoU2UwAdOtwUAYkjAAKm3CoEJBQJNXuTl6k8wuc2eN4axtbJCzWFAD0H8jYJHAGKCahzKABsGBQSuVKlBqgByOiwzhMC7TOyrOgsVgQ0oVaBwlKERHIqZDUirAmY2GqCAgkGElhAA" rel="nofollow noreferrer">Here</a> is an example from the TypeScript playground.</p>
  <pre class="lang-ts prettyprint-override"><code>interface myFunctions{
      one: () =&gt; number;
      two: () =&gt; number;
      echo: (str: string) =&gt; string;
  }
  
  const myFunctions: myFunctions = {
      one: () =&gt; 1,
      two: () =&gt; 2,
      echo: (str: string) =&gt; str
  }
  </code></pre>
  <p>This is my current wrapper definition:</p>
  <pre class="lang-ts prettyprint-override"><code>const wrapper = &lt;T extends keyof myFunctions&gt; (
      func: myFunctions[T]
  ) =&gt; (...args: Parameters&lt;myFunctions[T]&gt;) =&gt; func(...args)
  </code></pre>
  <p>And this is an example of how I would like to use the wrapper:</p>
  <pre class="lang-ts prettyprint-override"><code>wrapper&lt;'one'&gt;(myFunctions.one)()
  wrapper&lt;'echo'&gt;(myFunctions.echo)('hello')
  </code></pre>
  <p>Typescript does not accept my definition for the wrapper, as <code>Parameters&lt;myFunctions[T]&gt;</code> can be either an empty array or the parameter <code>str</code>, and the function <code>echo</code> expects a string.</p>
  <p>I am not very proficient in Typescript and went over the Typescript Handbook and could not find an answer. Similar questions regarding wrappers in StackOverflow were also not what I'm looking for.</p>
  <p>What is the correct way to define <code>wrapper</code>?</p>