title: Detect if click was inside react component or not in typescript
body: <p>I have roughly the following:</p>
  
  <pre><code>componentDidMount() {                                                                                                                                                                                           
    document.querySelector('body')!.addEventListener('click', this.click);
  } 
  
  click = (e: Event) =&gt; {                                                                                                                                                                                         
    if (this.state.toggled) {
      if (!ReactDom.findDOMNode(this.someRef).contains(e.target)) {
        this.setState({ toggled: false });
      }
    }
  };
  
  render() {
    return (&lt;CustomElement
      ref={(e) =&gt; { this.someRef = e; }}                                                                                                                                                                   
    /&gt;)
  }
  </code></pre>
  
  <p>This code correctly detects whether the user clicks inside or outside the CustomElement, so far so good.</p>
  
  <p>However, <code>tsc</code> isn't happy with this at all:</p>
  
  <pre><code>error TS2345: Argument of type 'EventTarget' is not assignable to parameter of type 'Node'.
    Property 'attributes' is missing in type 'EventTarget'.
  </code></pre>
  
  <p>Looking at <code>node_modules/typescript/lib/lib.d.ts</code> this makes sense, since <code>e.target</code> is an <code>EventTarget</code> which appears to only define the functions for adding and removing event handlers. However <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/target" rel="noreferrer">MDN</a> says e.target is "A reference to the object that dispatched the event." which sounds closer to what I want.</p>
  
  <p>So how do I retain the currently working functionality, while also making tsc happy (as opposed to just silencing the error)?</p>