title: Typescript: Type 'string' is not assignable to type 'never' in return value of function
body: <p>Basically I'm interested why does this example work:</p>
  
  <pre><code>interface Alpha {}
  interface Beta {}
  
  interface HelloMapping {
    'Alpha': Alpha
    'Beta': Beta  
  }
  
  const hello = &lt;T extends keyof HelloMapping&gt;(arg: T): HelloMapping[T] =&gt; 
  {
    if (arg === 'Alpha') return {} as Alpha;
    return {} as Beta;
  };
  
  const a = hello('Alpha') // a is of interface Alpha
  </code></pre>
  
  <p>But this one doesn't: </p>
  
  <pre><code>interface HelloMapping2 {
    'Alpha': string
    'Beta': number
  }
  
  const hello2 = &lt;T extends keyof HelloMapping2&gt;(arg: T): HelloMapping2[T] =&gt; 
  {
    if (arg === 'Alpha') return "42" as string
    return 42 as number
  };
  </code></pre>
  
  <p>It errors with <code>Type 'string' is not assignable to type 'never'</code> in the first line of function code.
  The only difference is changing interfaces to <code>string</code> and <code>number</code> types </p>
  
  <p>Please note, I know how to make that work with function overloads but I am curious why it does not work.</p>