title: TypeScript Conditional Types and Type Guards
body: <p>I'm having some problems combining TypeScript's type guards and conditional types.  Consider:</p>
  
  <pre><code>export interface IThisThing {
      someProp: number;
  }
  
  export function isIThisThing(type: any): type is IThisThing { 
      return !!type.someProp;
  }
  
  export interface IThatThing {
      someOtherProp: string;
  }
  
  export function isIThatThing(type: any): type is IThatThing { 
      return !!type.someOtherProp;
  }
  
  function doAThing&lt;T extends IThisThing | IThatThing&gt;(
      data: T
  ): T extends IThisThing ? IThisThing : IThatThing {
      if (isIThisThing(data)) { 
          return data; // Type 'T &amp; IThisThing' is not assignable to type 'T extends IThisThing ? IThisThing : IThatThing'.
      };
      return data; // Type 'T' is not assignable to type 'T extends IThisThing ? IThisThing : IThatThing'.
                   //   Type 'IThisThing | IThatThing' is not assignable to type 'T extends IThisThing ? IThisThing : IThatThing'.
                   //     Type 'IThisThing' is not assignable to type 'T extends IThisThing ? IThisThing : IThatThing'.
  }
  </code></pre>
  
  <p>I'd expect the <code>doAThing</code> function to accept <code>IThisThing</code> or <code>IThatThing</code> and to return the same type as it receives.  Alas the compiler chokes with messages along the line of: </p>
  
  <p><code>Type 'T &amp; IThisThing' is not assignable to type 'T extends IThisThing ? IThisThing : IThatThing'.</code></p>
  
  <p>Can someone set me straight? I feel I'm close but not quite getting it right.  I'm using the first example (which seems pretty similar) in this blog post: <a href="http://artsy.github.io/blog/2018/11/21/conditional-types-in-typescript/" rel="noreferrer">http://artsy.github.io/blog/2018/11/21/conditional-types-in-typescript/</a></p>