title: Create a function type template in Typescript
body: <p>I have a function that's something like the following except much less simple:</p>
  
  <pre><code>function foo(arg1?: string | number | boolean, arg2?: number | boolean, arg3?: boolean) {
    // omitted
  }
  </code></pre>
  
  <p>This function can be ran many different ways, for example:</p>
  
  <pre><code>foo();
  foo(1, true);
  foo("", false);
  foo(4);
  foo(true);
  // ..etc
  </code></pre>
  
  <p>In order to make context clues / type definitions readable, the best way is with overloads:</p>
  
  <pre><code>function foo();
  function foo(name: string);
  function foo(age: number);
  function foo(nice: boolean);
  function foo(name: string, age: number);
  function foo(name: string, nice: boolean);
  function foo(age: number, nice: boolean);
  function foo(name: string; age: number, nice: boolean);
  function foo(arg1?: string | number | boolean, arg2?: number | boolean, arg3?: boolean) {
    // omitted
  }
  
  // now it'll figure out which overload I'm on, and give easier to read insights
  </code></pre>
  
  <p>The <em>issue</em> is that I don't just have foo.  I have foo, bar, qux, baz, and 30 others.  It would be a terrible wall of text to write it all.  So I tried making one type for all, and it would work if it wasn't for generics:</p>
  
  <pre><code>// Without generics, this problem would be solved
  
  export const bar = (function(...args: ArgOutline) {
    // omitted
  }) as typeof foo
  
  export const qux = (function(...args: ArgOutline) {
    // omitted
  }) as typeof foo
  
  export const baz = (function(...args: ArgOutline) {
    // omitted
  }) as typeof foo
  
  /// and so on...
  </code></pre>
  
  <hr>
  
  <p>What I really want is an outline function which takes generics and can produce something that has readable insights, but the following code does not work:</p>
  
  <pre><code>function Outline();
  function Outline(name: string);
  function Outline&lt;PROPS&gt;(props: PROPS);
  function Outline(name: string props: PROPS);
  function Outline&lt;PROPS&gt;(arg1?: string | PROPS, arg2?: PROPS) {
    // omitted
  }
  
  
  // This doesn't work
  export const baz = (function(...args: ArgOutline) {
    // omitted
  }) as typeof Outline&lt;{a: number}&gt; 
  </code></pre>
  
  <p>I've read on why you can't do this (<a href="https://github.com/microsoft/TypeScript/issues/204" rel="nofollow noreferrer">https://github.com/microsoft/TypeScript/issues/204</a>), but it still seems there is a way, just not this way.</p>
  
  <p>How can I make a generic type which will produce insights that say <code>(+N overloads)</code> rather than <code>() =&gt; ReallyTerriblyLongName | (name: string) =&gt; ReallyTerriblyLongName | (name: string, props: AlsoATerriblyLongName) =&gt; ReallyTerriblyLongName | ...etc</code>?</p>