title: Match array return types with arbitrary number of inputs using generics
body: <p>If a user passes in type <code>[Iterable&lt;T&gt;]</code> I want to return type <code>[T]</code> and if the user passes in <code>[Iterable&lt;T&gt;, Iterable&lt;U&gt;]</code> I want to return type <code>[T, U]</code>. I want to continue this for any number of elements in the input array.</p>
  <p>Is there a way to define the types for the following function generically so that it will work for any number of inputs rather than continuing to define overloads of the function with increasing numbers of generic?</p>
  <p>Here's what I have so far, but of course it only supports up to 5 inputs as defined. Can I make it work for an arbitrary number of inputs?</p>
  <pre><code>export function linkIterables&lt;T&gt;(
    iterables: [Iterable&lt;T&gt;],
  ): Iterable&lt;[T]&gt;;
  export function linkIterables&lt;T, U&gt;(
    iterables: [Iterable&lt;T&gt;, Iterable&lt;U&gt;],
  ): Iterable&lt;[T, U]&gt;;
  export function linkIterables&lt;T, U, V&gt;(
    iterables: [Iterable&lt;T&gt;, Iterable&lt;U&gt;, Iterable&lt;V&gt;],
  ): Iterable&lt;[T, U, V]&gt;;
  export function linkIterables&lt;T, U, V, W&gt;(
    iterables: [Iterable&lt;T&gt;, Iterable&lt;U&gt;, Iterable&lt;V&gt;, Iterable&lt;W&gt;],
  ): Iterable&lt;[T, U, V, W]&gt;;
  export function linkIterables&lt;T, U, V, W, X&gt;(
    iterables: [Iterable&lt;T&gt;, Iterable&lt;U&gt;, Iterable&lt;V&gt;, Iterable&lt;W&gt;, Iterable&lt;X&gt;],
  ): Iterable&lt;[T, U, V, W, X]&gt;;
  export function* linkIterables&lt;T&gt;(
    iterables: Iterable&lt;Iterable&lt;T&gt;&gt;,
  ): Iterable&lt;T[]&gt; {
    const iters = [...iterables].map(u =&gt; u[Symbol.iterator]());
    while (true) {
      let done = true;
      const results = [];
      for (const iter of iters) {
        const result = iter.next();
        if (!result.done) {
          done = false;
        }
        results.push(result.value);
      }
      if (done) {
        return results;
      }
      yield results;
    }
  };
  </code></pre>