title: TypeScript: Conditional generic types as function return values not assignable
body: <p>I have a problem with assignable values in one of my generic functions: </p>
  
  <pre><code>interface BuildArguments&lt;T extends string&gt; {
      type: T;
  }
  
  type PromiseResult&lt;T&gt; =
      T extends 'standalone' ? Promise&lt;void&gt; :
      T extends 'all' ? Promise&lt;void&gt; :
      Promise&lt;void[]&gt;;    
  
  const foo: PromiseResult&lt;'standalone'&gt; = Promise.resolve();
  const bar: PromiseResult&lt;'all'&gt; = Promise.resolve();
  const baz: PromiseResult&lt;'foo'&gt; = Promise.resolve([]);
  
  bundle({ type: 'foo' });
  
  function bundle&lt;T extends string&gt;(buildArguments: BuildArguments&lt;T&gt;): PromiseResult&lt;T&gt; {
      switch (buildArguments.type) {
          case 'standalone':
              return Promise.resolve(); // error here, not assignable to PromiseResult&lt;T&gt;
          case 'all':
              return Promise.resolve(); // error here, not assignable to PromiseResult&lt;T&gt;
          default:
              return Promise.all([ // error here, not assignable to PromiseResult&lt;T&gt;
                  Promise.resolve(),
                  Promise.resolve()
              ]);
      }
  }
  </code></pre>
  
  <p>The <code>const</code>s <code>foo</code>, <code>bar</code> and <code>baz</code> show that the conditional type works fine. the function call <code>bundle({ type: 'foo' })</code> also correctly provides the type <code>Promise&lt;void[]&gt;</code> if you use the ts playground and hover over it. Why doesn't it work for the return values?
  I also tried if this is caused by TypeScript not being able to infer <code>T</code> by adding a <code>kind: T</code> argument to the function, but no changes. Asserting <code>Promise.resolve()</code> to <code>PromiseResult&lt;T&gt;</code> works fine.</p>