title: Nested wrapper functions are returning Promise<Promise<T>>
body: <p>I have a wrapper function (<code>doesPromiseyThings</code>) that takes a thunk and returns the thunk's return value inside a Promise. I'd like to create another wrapper that handles creation of the thunks - creates a function that takes the same parameters as the original, returns the Promise-wrapped type of the original, and passes the function through <code>doesPromiseyThings</code> when it's executed.</p>
  <p>When I try to do this, passing in a function that returns a promise, my returned types are all <code>Promise&lt;Promise&lt;T&gt;&gt;</code>, which TypeScript complains isn't the same as the <code>Promise&lt;T&gt;</code> I'm trying to assign the return value to.</p>
  <pre class="lang-js prettyprint-override"><code>async function foo(param: number) {
      return param;
  }
  
  function doesPromiseyThings&lt;T&gt;(fn: () =&gt; T): Promise&lt;T&gt; {
      return Promise.resolve(fn());
  }
  
  function wrapper&lt;T,U&gt;(fn: (...args: T[]) =&gt; U) {
      return (...args: T[]) =&gt; doesPromiseyThings(fn);
  }
  
  const wrappedFoo = wrapper(foo);
  // (...args: number[]) =&gt; Promise&lt;Promise&lt;number&gt;&gt;
  
  const output = wrappedFoo(1);
  // Promise&lt;Promise&lt;number&gt;&gt;
  </code></pre>
  <p>I tried unwrapping the Promise in the wrapper's return value, but I get type errors doing that:</p>
  <pre class="lang-js prettyprint-override"><code>function wrapper&lt;T,U&gt;(fn: (...args: T[]) =&gt; U): (...args: T[]) =&gt; Promise&lt;U extends Promise&lt;infer V&gt; ? V : U&gt; {
      return (...args: T[]) =&gt; doesPromiseyThings(fn);
  }
  /*
  Type '(...args: T[]) =&gt; Promise&lt;U&gt;' is not assignable to type '(...args: T[]) =&gt; Promise&lt;U extends Promise&lt;infer V&gt; ? V : U&gt;'.
    Type 'Promise&lt;U&gt;' is not assignable to type 'Promise&lt;U extends Promise&lt;infer V&gt; ? V : U&gt;'.
      Type 'U' is not assignable to type 'U extends Promise&lt;infer V&gt; ? V : U'.(2322)
  */
  </code></pre>