title: how to use 'or' operator when dealing with two different types
body: <p>I have a function that takes an argument with two types.</p>
  <p>Refer to the typsescript <a href="https://www.typescriptlang.org/docs/handbook/functions.html" rel="nofollow noreferrer">docs</a>, <a href="https://stackoverflow.com/questions/51851677/how-to-get-argument-types-from-function-in-typescript">this</a> SO question, and <a href="https://stackoverflow.com/questions/12776625/can-i-specify-parameter-type-as-one-of-many-types-instead-of-any-type-in-typescr">this</a> SO question related to TS functions and types.</p>
  <h3>Function</h3>
  <pre><code>  public onKeydown(ev: KeyboardEvent | EventTarget): void {
      if (ev.keyCode === 13) {
        this.sendMessage();
        ev.target.blur();
      } else {
        this.chatService.emitTyping();
      }
      return;
    }
  </code></pre>
  <h3>HTML for the page</h3>
  <pre><code>          &lt;textarea
              autosize
              [minRows]=&quot;1&quot;
              [maxRows]=&quot;4&quot;
              [(ngModel)]=&quot;message&quot;
              placeholder=&quot;escribe aqui&quot;
              class=&quot;msg-input&quot;
              (keydown)=&quot;onKeydown($event)&quot;
              (click)=&quot;scrollToBottom()&quot;
            &gt;&lt;/textarea&gt;
  </code></pre>
  <p>I cannot see that the function <code>onKeyDown</code> has two different types. Because the <code>or</code> doesn't seem to have the same effect in Angular as the docs of Typescript say. For example, if the 'Enter' key is pressed then <code>blur()</code> the keyboard and send the message. Am I going to have to make a separate function just to blur the keyboard?</p>
  <p>This is the error I am getting:</p>
  <blockquote>
  <p>ERROR in src/Components/chat/chat.component.ts(72,12): error TS2339: Property 'keyCode' does not exist on type 'EventTarget | KeyboardEvent'.</p>
  <p>[ng]   Property 'keyCode' does not exist on type 'EventTarget'.</p>
  <p>[ng] src/Components/chat/chat.component.ts(74,10): error TS2339: Property 'target' does not exist on type 'EventTarget | KeyboardEvent'.</p>
  <p>[ng]   Property 'target' does not exist on type 'EventTarget'.</p>
  </blockquote>