title: TypeScript: Omit trailing parameter of generic function when its type is undefined
body: <p>Is it possible to configure TypeScript to allow omitting the trailing parameter of a generic function if the trailing parameter's type is <code>undefined</code> (but not if it isn't)?</p>
  <p>Example:</p>
  <pre><code>type Events = {
    readonly first: { readonly foo: string};
    readonly second: undefined;
  }
  
  const sendEvent = &lt;Name extends keyof Events&gt;(name: Name, payload: Events[Name]) =&gt; {
    console.log(`SEND EVENT &quot;${name}&quot;`, name, payload);
  }
  
  sendEvent('first', { foo: 'bar'}); // &lt;-- OK
  
  sendEvent('second', undefined); // &lt;-- OK
  
  sendEvent('first');  // &lt;-- Error as expected, Events[&quot;first&quot;] isn't undefined,
                       // that's good
  sendEvent('second'); // &lt;-- Error: 'Expected 2 arguments, but got 1.'
                       // would like to not have an error here, since
                       // Events[&quot;second&quot;] is undefined
  </code></pre>