title: Type safe way to check instanceof while working with iframes?
body: <p>I have a code base type checked by Flow, and I use <code>instanceof</code> a lot to do type refinements.</p>
  
  <p>I now need to make my code work when elements come from iframes, and <code>instanceof</code> doesn't work in this case, <a href="https://stackoverflow.com/questions/26248599/instanceof-htmlelement-in-iframe-is-not-element-or-object">because each window has its own instances</a>.</p>
  
  <p>I tried to define a <code>getOwnElement</code> helper to get <code>Element</code> from <code>defaultView</code>, but if I then use the retrieved <code>Element</code> the <code>instanceof</code> check fails for Flow:</p>
  
  <pre class="lang-js prettyprint-override"><code>declare function getOwnElement(node: Element): Element;
  function getOwnElement(node) {
    return node.ownerDocument.defaultView.Element;
  }
  
  const ownElement = getOwnElement(element);
  element instanceof ownElement &amp;&amp; element; // element is marked as `empty`
  </code></pre>
  
  <p>So now I'm wondering how am I supposed to update my code to keep it type safe and work with iframes?</p>