title: Variadic kinds in typescript?
body: <p>I want my function <code>memoize(fn)</code> to return another function with the same type as <code>fn</code>.</p>
  
  <p>I have an ugly solution like the following:<br>
  Whats the right way to write variadic generics?</p>
  
  <pre><code>export const memoize = &lt;FN&gt;(fn: FN) : FN =&gt; {
    const cache = { };
    const run : any = (...args) =&gt; {
      const key = JSON.stringify(args);
      if(!cache[key]) {
        cache[key] = (fn as any)(...args).catch(up =&gt; {
          delete cache[key];
          throw up;
        });
      }
      return cache[key];
    };
    return run as FN;
  }
  
  const get = memoize((url: string) =&gt; fetch(url, {method: 'GET'}));
  </code></pre>