title: Resolve multiple callback and promises in a tuple with the right type
body: <p>Here is a playground with the <a href="https://www.typescriptlang.org/play?ssl=1&amp;ssc=1&amp;pln=40&amp;pc=134#code/PQKgUAKgFgpgBAMwJYCcDOAXOAbGBzOAewTgFsBPOABxUICNdS4k04pCB3ODQuPGLChhpC2AG7xSAV2wYkVXHADGAQ2zY6KpQGtWSAHY8i++Ain6lcwvrgr9AEz4DusOELQyMrFd+WEUQpbYlBjkVDCOGFIKMGAgwGBgBhgwKAha8ABSAIpSqeQAIjAIqUL2ADwQAHxwAN5gcI1wYmp5AFxwEGAAvnDAwHAAVlKYiP4u8DAAHiqkMdy8QqSEEhNwpf6JZhZWNu6iEuUAwmoaWrrrUykO3vrkANoAulUAFAB0H9uWSNZoHSfqTQ6NAASjqDSauEEwk8rAAvHAngBuCGNBD+F5KX5YEjERDmb6-MH1Jqktww2RoN5UEZQF4IF4gkEo0ndVHkqIoPYUrwotlgLH6UYIACMcARjPFNRFKMFwoATOK4JK4TUAESYFBqlFgKFuJX7cQwekigA0iHlzL6AxQzFYeNC4Vsdye5oAkgByRzYJDaeBILBGOjwB1heD3fRSUjBlDmzUGPCPAW-UQwN7YQh4F4oZmJUCQVxoGCCxxUFQoLAsOAcANQai0UgsYRvOAAMXGGFcgX8jjdcBG8DsRGwjgk6B+NjxOTyKEo6NtuDwWkoQh8vzgIjYnDgfYHcGn+SKJQCETIKkowaIUgw9hUKXsbziCTAX125JERoAsnZyJVzQAlV5yzwP591yQ9ilKCJKiqJ4QQ6f8njqa04H0QgsFOTpnUcf9bCENY0FmeA6GvHc4HsawPSwbQ0K4dguCMaYaGEVhOzvdk9XcWEOh-JCEWRdl+jYVJ4A4eAsTma94E7eAuMpd0cEgwMoDvK8sAdVxplmGJ2SETluQ8Sk+USPV7GKABlDAUATABCDoD1nI8oIqeN9DwKokRQzsqzM49TxrdQOSkLlbA3KyE3NKEPVYQjKDVXy1V1ZxfIAOSjGM7LAmdCkgk8KkjaNUg8ryoB83L-KQQK9OCmwVFQ9LUkigRoo3c84AAFnlEznACA1hAOGBvzuF57l8yzrLc81UoalBHitISAuwIKQvueLijVc1OqTISAAkRLIvB0LgRUaHoRg0HNCBzKOPw5mwFQDG8OhCFI6bCttYMEyIEhHSycDHNyspygKmMqgU8wzPQDA7EcDgoAvUiAxazBKqWhhCB0L75zINMwCEgBBBw3FtKtQydcwaM4fRXTIjgXpHHBfVk20g2ksNvFYe5XLwc0QdSJMksEXqEUNCQhvIEaxvCybyOKNL3qmuWZrmzyhO8mL2BkRw1E3OmUG0bDidtNBNYZy8yfDbneZm633seIA" rel="nofollow noreferrer">code</a>.</p>
  <p>The first leg of my problem is how to get resolve multiple callbacks into one function and get the results as a correctly typed tuple</p>
  <pre><code>interface JQueryDeferred&lt;T&gt; {
      value: T
  } // just for the example to remove the error
  
  function resolve&lt;Callbacks extends any[]&gt;(...functions: Callbacks) {
      let results = [];
      for(const f of functions) {
          results.push(f());
      }
      return results;
  }
  
  const f1 = () =&gt; 1;
  const f2 = () =&gt; &quot;str&quot;;
  
  let r = resolve(f1, f2); // r is of type any[], I'd like it to be of type [number, string]
  console.log(r);
  </code></pre>
  <p>Also, how would you do it if resolve were taking an array directly instead of varargs?</p>
  <p>The second part is with promises. For the record I use an old version of JQuery for legacy reasons so how I use JQueryDeferred may be outdated.</p>
  <pre><code>function resolveMany&lt;T, R&gt;(args: JQueryDeferred&lt;T&gt;[]): R[] { // not all T and R are the same but I don't know how to express that
      let results: any[] = [];
      // here we compute the results, I lefet that out of the example
      return results;
  }
  
  let defString!: JQueryDeferred&lt;string&gt;; // this defered will return a string, let's say &quot;def&quot;
  let defNumber!: JQueryDeferred&lt;number&gt;; // this defered will return a number, let's say 42
  
  let rr = resolveMany([defString, defNumber]); // will return [&quot;def&quot;, 42]
  // Here I got 2 problems, TSC complains about defNumber being of type JQueryDeferred&lt;number&gt;, I understand why but it's still blocking for me.
  // And rr is of type unknown[], I would like rr to be types as [string, number]
  
  let rrr = resolveMany([defString, defNumber, defNumber]); // this should also work and rrr should be of type [string, number, number]
  </code></pre>
  <p>Is there any way to do all that in typescript?</p>