title: Conditional data types on union data types
body: <p>Assume that you have the following types:</p>
  <pre class="lang-js prettyprint-override"><code>type Foo = {
      prop1: 'foo',
      prop2: null
  }
  
  type Bar = {
      prop1: 'bar',
      prop2: number
  }
  
  type FooOrBar = Foo | Bar
  </code></pre>
  <p>Is it possible to rewrite the above code using conditional types?</p>
  <p>I have tried the following:</p>
  <pre class="lang-js prettyprint-override"><code>type FooOrBar = {
      prop1: 'foo' | 'bar'
      prop2: FooOrBar['prop1'] extends 'foo' ? null : number
  }
  </code></pre>
  <p>But when trying to declare a var like so:</p>
  <pre class="lang-js prettyprint-override"><code>const sample1: FooOrBar = {
      prop1: 'foo',
      prop2: null
  }
  </code></pre>
  <p>I receive the following error:</p>
  <blockquote>
  <p>Type 'null' is not assignable to type 'number'.</p>
  </blockquote>
  <p>It seems that <code>FooOrBar['prop1'] extends 'foo'</code> is always <code>false</code> which shouldn't be since <code>FooOrBar['prop1']</code> is a union type of <code>'foo' | 'bar'</code></p>
  <p>What am I doing wrong?</p>