title: React Flowtype Node.contains() Event Target
body: <p>I have this event listener in React:</p>
  
  <pre><code>document.removeEventListener("mouseup", this.handleDocumentClick);
  </code></pre>
  
  <p>This is one of the definitions of this method as per <a href="https://github.com/facebook/flow/blob/v0.63.1/lib/dom.js" rel="noreferrer">Flow's source code</a>:</p>
  
  <pre><code>removeEventListener(type: MouseEventTypes, listener: MouseEventListener, optionsOrUseCapture?: EventListenerOptionsOrUseCapture): void;
  </code></pre>
  
  <p>It seems the listener must be of type <code>MouseEventListener</code>:</p>
  
  <pre><code>type MouseEventHandler = (event: MouseEvent) =&gt; mixed
  type MouseEventListener = {handleEvent: MouseEventHandler} | MouseEventHandler
  </code></pre>
  
  <p>So it seems that I can type it like this:</p>
  
  <pre><code>handleDocumentClick = (evt: MouseEvent) =&gt; {
  
  }
  </code></pre>
  
  <p>So far, no Flow errors. Now, I want to check if the event's target is inside another DOM node that I have stored in a <a href="https://reactjs.org/docs/refs-and-the-dom.html" rel="noreferrer">React Ref</a>:</p>
  
  <pre><code>$menu: React.ElementRef&lt;typeof Menu&gt;;
  
  handleDocumentClick = (evt: MouseEvent) =&gt; {
      if (this.$menu !== null) {
          const menu = ReactDOM.findDOMNode(this.$menu);
  
          if (menu) {
              console.log(menu.contains(evt.currentTarget));
          }
      }
  }
  </code></pre>
  
  <p>And I get this error:</p>
  
  <pre><code> 54:                     console.log(menu.contains(evt.currentTarget));
                                                     ^^^^^^^^^^^^^^^^^ EventTarget. This type is incompatible with the expected param type of
  447:   contains(other: ?Node): boolean;
                          ^^^^ Node. See lib: /private/tmp/flow/flowlib_3e761601/dom.js:447
  </code></pre>
  
  <p>The <code>contains</code> method should work for the target of an event (which is a DOM node). What could be wrong here – perhaps the definition of <code>contains</code> in Flow?</p>