title: Typescript: pass Parameters<T> tuple of generic function type parameter as variadic arguments
body: <p>In Typescript 4.1.x you can <a href="https://devblogs.microsoft.com/typescript/announcing-typescript-4-0/#variadic-tuple-types" rel="nofollow noreferrer">spread tuple types</a> into functions as variadic arguments.</p>
  <pre class="lang-js prettyprint-override"><code>type MyTuple = [string, number];
  const myTuple: MyTuple = [&quot;blob&quot;, 42];
  
  function tupleFunc(s: string, n: number): void {
      console.log(`${s} ${n}`);
  }
  
  tupleFunc(...myTuple); // ✅ A-Ok
  </code></pre>
  <p>However, I'm hitting an error when the tuple is derived from a generic type parameter and using the <a href="https://www.typescriptlang.org/docs/handbook/utility-types.html#parameterstype" rel="nofollow noreferrer"><code>Parameters&lt;T&gt;</code> utility type</a>.</p>
  <pre class="lang-js prettyprint-override"><code>function foo(a: number, b: boolean, c: string) {
    return 10;
  }
  
  foo(1, true, &quot;baz&quot;) // 10 ✅
  
  function bar(...params: Parameters&lt;typeof foo&gt;) {
      return foo(...params)
  }
  
  bar(1, true, &quot;baz&quot;) // 10 ✅
  
  function bar2&lt;F extends typeof foo&gt;(...params: Parameters&lt;F&gt;) {
    //  next line would work
    //  return foo(params[0], params[1], params[2])
  
    return foo(...params); // Fails 
    // Expected 3 arguments, but got 0 or more.ts(2556)
    // index.ts(28, 14): An argument for 'a' was not provided.
  }
  </code></pre>
  <p>Is there a way to make this concept pass the type checker or is it not supported in typescript? Although it errors, it seems to work in the Typescript sandbox. <a href="https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABMOcAUBDAXIsIC2ARgKYBOANIoToagDbEZiUQ4DOUpMYA5gJTtO3HogDeAKESJSxKCFJIABmxAQIxNm0QASURgC+O0YUO6I+xQG5x+8eIgI2cBgDo6cHmgBEKOF77WDmBOru6evmgAjJScIMSUXoQYAF7+fHagkLAIVBikaC6FAA55GPhsOAAKpfiyZGwAPFAAnkXEcMDIqAB8fGKSUtKy8kgRhS4lpGVs6bb2js7Ebh7eSaT+gQuhK2tRMaRxCUmpfOnimdDwSGsATA0AYojEAB5QxGAAJlotbR1dcN0CsUahVENUprU3qRGvdev0pAB6BFSMAvKCIOjcYiIADucFIAGs2AMkVIZHIFP80JNpgBtAAMAF1KDTyrTIszEKy2LSboz0ojkajXhisYgPnANGAAORQAbkkZU8bcgI2OxBEJLMKrPI3fzzYKLZaeW57RCxeKIRIpNIZcCXHJrADMDQAKk9Xu8vubWu1Or5AcqQVUanVoW64RIycNKb4XBgikU6M00L4WSDVbYNUbtdbSE6NgbNca0M6zRajnk0tZxD9sQAlRAAXkQ9ZjYFdvqavr+zu6dgY6NIOEbLZuQA" rel="nofollow noreferrer">See an example here.</a></p>
  <p>Seems like I can get it to work with <code>.apply()</code>, but I'd love to know if there's another way.</p>
  <pre><code>function bar3&lt;T extends typeof foo&gt;(...params: Parameters&lt;T&gt;) {
    return foo.apply(null, params);
  }
  </code></pre>