title: Optional parameters based on conditional types
body: <p>Is it possible to make a function have either mandatory or optional parameters based on conditional types in TypeScript?</p>
  
  <p>This is what I've got so far:</p>
  
  <pre><code>const foo = &lt;T extends string | number&gt;(
      first: T,
      second: T extends string ? boolean : undefined
  ) =&gt; undefined;
  
  foo('foo', true); // ok, as intended
  foo(2, true); // not ok, as intended
  foo(2, undefined); // ok, as intended
  foo(2); // compiler error! I want this to be ok
  </code></pre>