title: Typescript local variable inference after if check
body: <p>I have a question about type inference. Why it doesn't work on a sample below? Error says that return type of <code>IMapT[T]</code> is inferred to <code>T1 &amp; T2</code> even when there's an explicit if statements on value of <code>T</code>. When value of <code>T</code> is known as one of enum values, I expect return type to expect <code>T1</code> or <code>T2</code> interface respectively to the <code>IMapT</code> interface.</p>
  <pre class="lang-js prettyprint-override"><code>enum EModule {
    T1 = 0,
    T2 = 1,
  }
  
  interface T1 {
    a: number
  }
  interface T2 {
    b: string
  }
  
  interface IMapT {
    [EModule.T1]: T1
    [EModule.T2]: T2
  }
  
  function check&lt;T extends EModule&gt; (p: T): IMapT[T] | null {
    if (p === EModule.T1) {
      return {
        a: 10,
      }
    }
    if (p === EModule.T2) {
      return {
        b: '',
      }
    }
    return null
  }
  
  const x = check(EModule.T1)
  ``
  </code></pre>