title: Incorrect return type for conditional generics
body: <p>I'm attempting to write a function that returns a value using generics and conditional types like so:</p>
  <pre><code>interface Foo&lt;T&gt; {
    bar: T extends true ? string : undefined;
    id: string;
  }
  
  interface Options&lt;T&gt; {
    withBar?: T;
  }
  
  function createFoo&lt;T extends boolean&gt;({ withBar }: Options&lt;T&gt;): Foo&lt;T&gt; {
    return {
      id: 'foo',
      ...(withBar &amp;&amp; { bar: 'baz' }),
    };
  }
  </code></pre>
  <p>The above throws the following type error:</p>
  <pre><code>Type '{ bar?: &quot;baz&quot; | undefined; id: string; }' is not assignable to type 'Foo&lt;T&gt;'.
    Types of property 'bar' are incompatible.
      Type '&quot;baz&quot; | undefined' is not assignable to type 'T extends true ? string : undefined'.
        Type 'undefined' is not assignable to type 'T extends true ? string : undefined'.
  </code></pre>
  <p>Can someone help me understand why this is the case? I'm specifying that the type can be undefined, so it should be allow to be undefined.</p>
  <p>Additionally I'd like to get the return type of the function given certain params without actually calling it. Is that possible?</p>
  <p>e.g. <code>ReturnType&lt;typeof createFoo&gt;</code> won't give me the correct type for usage <code>createFoo({ withBar: true })</code> because it doesn't know about the usage yet.</p>
  <p><a href="https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgGIHt0B4AqA%20ZAbwChlkAjOKALmR2QgA9IQATAZ2TCgFcUB%20ZO26gA5slo82EGKAisA3KWTBWtYVDFKAvsWKhIsRCgDyABzDB0IdrgIkyAd2BgAFgCEq-Wjh16YUgiW1sgIUBBwkBjY9EwsHBSYADYRIHgAFITIzm6eUMjatObBNnYAlLTRdkTK4WA8UCA1ZGSqtADkMJjtADTKZAB0Q%20k5HlTIAGQTRBRUHZQAXu0FZX1k2n5AA" rel="nofollow noreferrer">Live example here</a></p>