title: create generic type from generic function
body: <p>I'm trying to declare a generic type based on another generic type without success.</p>
  
  <p>The objective is the write my own test framework and to type some parameters depending on another one (the method).</p>
  
  <pre class="lang-js prettyprint-override"><code>type Arguments&lt;T&gt; = T extends (...args: infer U) =&gt; any ? U : never;
  
  // my custom test method
  const methodCall = &lt;T extends (...args: any) =&gt; any&gt;(args: {
    method: T;
    response: ReturnType&lt;T&gt;;
    myArguments: Arguments&lt;T&gt;;
  }): boolean =&gt; {
    const { method, myArguments, response } = args;
    return method.apply(null, myArguments) === response;
  };
  
  const test1 = (toto: string) =&gt; {
    return toto === "success";
  };
  
  // usage of my custom function
  methodCall({
    method: test1,
    myArguments: ["fail"],
    response: false
  });
  
  
  // this is what I want to type
  interface MyHelpers {
    methodCall: any // HOW TO TYPE THIS? 
    methodCall2: (args: { flag: boolean }) =&gt; boolean;
  }
  
  // I would expose only the helpers object
  const helpers = (): MyHelpers = {
    methodCall: &lt;T extends (...args: any) =&gt; any&gt;(args: {
      method: T;
      response: ReturnType&lt;T&gt;;
      myArguments: Arguments&lt;T&gt;;
    }): boolean =&gt; {
      const { method, myArguments, response } = args;
      return method.apply(null, myArguments) === response;
    },
    methodCall2: (args: { flag: boolean }): boolean =&gt; {
      return args.flag;
    }
  };
  
  </code></pre>
  
  <p>I'm expecting another object calling helpers to be able with <code>helpers().methodCall(...)</code> to be typed as it is declared in helpers. Not with <code>any</code>.</p>
  
  <p>The playground can be found <a href="https://www.typescriptlang.org/play/#code/C4TwDgpgBAggTgcwK4FsIDtgGcA8AVAPigF4o8oIAPYDAEyygAoA6VgQ0SwC4oBLdAGYQ4UAKoBKEkTboQUAPxioPdBABuwgNwAobQGMA9uizAoaYAAsDtAMJsANvZJR8FanQYt2nHjJCTiaVkCRg4EbigAb20oMwhLax48HVi4CCwwIywIHgAleKQ4dDxwCHwCFLMQeGQ0TAia1Axscp0AX3EeACMDA3sIGSkomKhDY1NIuITaABoqxrrsObSMrOg25zCsSrTgQvQpq1pmNjAwexBGdCRHOZRqxCb6gOJSFczjCHadfSzTGhMAEZnIxgAYwTwTHB+AgAkRoqkCkUoGCwSRXlAAERYJB6PTpLCY766cxHOyORgIw6JFHpYCAmYje4LZoRADamIEbF49kxAF1GYjVp8eFz7NltB0ftp+DQ4Fz8VAALIgAASEHskDgDCppOs5PsvlkUAA9CaoKqAPIAdTIlrIAE0AAoAUTIqoAkgBlRRM+Jkhz2ABMPFCPiiUAE9jYCG6vX6gw6Qx6fQG6HaujGJigFg1WoiKvVmuEDFIuv9+sDPFcVBo6HoTFYJ3DfjhUD8IS2PCpsT1tCSlSFH2yeSRxVKrRGvYetVZPBZ9UnsQ6cdTg0Cw1isSzE2ps3mj0WWGW6WH602nEHUF2+z3JzOFyuN3sdxnT2wLzep7WlTagr3BohkwXYRlGMargmBwrlAKaQUMPbXmO7acMwYEIL+ko6EAA" rel="nofollow noreferrer">here</a>. </p>
  
  <p>thanks!</p>