title: Typescript addEventListener set event type
body: <p>I'm trying to do this</p>
  <pre><code>document.addEventListener('click', (e: MouseEvent) =&gt; { ...
  </code></pre>
  <p>However, Typescript cannot know the exact event type based on event name.</p>
  <p><code>'click'</code> =&gt; <code>MouseEvent</code></p>
  <p>and thinks the type of <code>e</code> is of type <code>Event</code>. As is in definition</p>
  <pre><code>declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
      
  interface EventListener {
      (evt: Event): void;
  }
      
  interface EventListenerObject {
      handleEvent(evt: Event): void;
  }
  </code></pre>
  <p>It obviously complains</p>
  <blockquote>
  <p>TS2345: Argument of type '(e: MouseEvent) =&gt; void' is
  not assignable to parameter of type
  'EventListenerOrEventListenerObject'.   Type '(e: MouseEvent) =&gt; void'
  is not assignable to type 'EventListener'.
  Types of parameters 'e' and 'evt' are incompatible.
  Type 'Event' is missing the following properties from type 'MouseEvent': altKey, button, buttons, clientX, and 25 more.</p>
  </blockquote>
  <p>How can I tell Typescript the <code>e</code> is of type <code>MouseEvent</code>? Or if I asked more generally: how to type <code>addEventListener</code> properly?</p>