title: Type Narrowing an element in an array with `find`
body: <p>If I have an array filled with items of a union type and I want to find an element within the array and work with it, knowing from my <code>find</code> that I have narrowed the type, how do I accomplish this?</p>
  
  <p>That is, if I have the following types:</p>
  
  <pre><code>interface A {
    text: string;
  }
  interface B {
    type: string;
  }
  type C = A|B;
  </code></pre>
  
  <p>and the following code</p>
  
  <pre class="lang-js prettyprint-override"><code>const arr: Array&lt;C&gt; = [....]
  </code></pre>
  
  <p>I want to find the first element of <code>arr</code> that has a <code>type</code> attribute.</p>
  
  <p>Logically, I think this is represented by</p>
  
  <pre class="lang-js prettyprint-override"><code>const output = arr.find(child =&gt; {
    if ('type' in child) return true;
    return false
  })
  </code></pre>
  
  <p>This seems like it should narrow the type of <code>output</code> to be <code>B</code>, but it doesn't. The compiler still seems to think that <code>output</code> is of type <code>C</code>.</p>