title: Is it possible to use the return type of a function within that function's argument types?
body: <p>For example, when I try to do this:</p>
  <pre><code>function chain&lt;A, B extends (input: A, loop: (input: A) =&gt; C) =&gt; any, C extends ReturnType&lt;B&gt;&gt; (input: A, handler: B): C {
     const loop = (input: A): C =&gt; handler(input, loop);
     return loop(input);
  }
  
  chain('test', async (value, loop): Promise&lt;string&gt; =&gt; {
     const ready = await someExternalThing();
     if (ready) {
        return value;
     } else {
        return await loop(value + '!');
     }
  });
  </code></pre>
  <p>Even with a strict return type defined for the handler function, the loop function's return type in the bottom code is still showing up as &quot;any&quot;</p>
  <p>Does anybody know any way around this issue?</p>