title: Varargs in typescript
body: <p>I want to pass arbitrary number of arguments of different types into a function and use these types. It looks <a href="http://www.typescriptlang.org/play/#src=%250D%250Afunction%2520f%3CA%3E(a%253A%2520A)%253A%2520A%253B%250D%250Afunction%2520f%3CA%252C%2520B%3E(a%253A%2520A%252C%2520b%253A%2520B)%253A%2520A%2520%2526%2520B%253B%250D%250Afunction%2520f%3CA%252C%2520B%252C%2520C%3E(a%253A%2520A%252C%2520b%253A%2520B%252C%2520c%253A%2520C)%253A%2520A%2520%2526%2520B%2520%2526%2520C%253B%250D%250Afunction%2520f%3CA%252C%2520B%252C%2520C%252C%2520D%3E(a%253A%2520A%252C%2520b%253A%2520B%252C%2520c%253A%2520C%252C%2520d%253A%2520D)%253A%2520A%2520%2526%2520B%2520%2526%2520C%2520%2526%2520D%253B%250D%250A%250D%250Afunction%2520f(...args%253A%2520any%255B%255D)%2520%257B%250D%250A%2520%2520%2520%2520return%2520Object.assign(%257B%257D%252C%2520...args)%253B%250D%250A%257D%250D%250A%250D%250Avar%2520smth%2520%253D%2520f(%257B%2520x%253A%25201%2520%257D%252C%2520%257B%2520y%253A%25202%2520%257D%252C%2520%257B%2520z%253A%25203%2520%257D)%253B%250D%250Avar%2520res%2520%253D%2520smth.x%2520%252B%2520smth.y%2520%252B%2520smth.z%253B" rel="noreferrer">like following</a>:</p>
  
  <pre><code>function f&lt;A&gt;(a: A): A;
  function f&lt;A, B&gt;(a: A, b: B): A &amp; B;
  function f&lt;A, B, C&gt;(a: A, b: B, c: C): A &amp; B &amp; C;
  function f&lt;A, B, C, D&gt;(a: A, b: B, c: C, d: D): A &amp; B &amp; C &amp; D;
  
  function f(...args: any[]) {
      return Object.assign({}, ...args);
  }
  
  var smth = f({ x: 1 }, { y: 2 }, { z: 3 });
  var res = smth.x + smth.y + smth.z;
  </code></pre>
  
  <p>As I want arbitrary number of parameters, I'd like to get rid of these declarations</p>
  
  <pre><code>function f&lt;A&gt;(a: A): A;
  function f&lt;A, B&gt;(a: A, b: B): A &amp; B;
  function f&lt;A, B, C&gt;(a: A, b: B, c: C): A &amp; B &amp; C;
  function f&lt;A, B, C, D&gt;(a: A, b: B, c: C, d: D): A &amp; B &amp; C &amp; D;
  </code></pre>
  
  <p>and use a single declaration like:</p>
  
  <pre><code>function f&lt;...T&gt;(args: [...T]): &amp;&lt;...T&gt;;
  </code></pre>
  
  <p>but this thing is syntactically wrong.</p>
  
  <p>Is there a way to rewrite it in a correct way?</p>
  
  <p>PS: <a href="//ru.stackoverflow.com/q/838771/178988">Same question in Russian.</a></p>