title: Typescript - check type in runtime and warn about errors
body: <p><strong>INTRODUCTION</strong></p>
  
  <p>I'm using Angular 6.</p>
  
  <p>Angular uses typescript, so you can type your function's arguments:</p>
  
  <pre><code>public fun1(aaa: number) {
    console.log(aaa);
  }
  </code></pre>
  
  <p>If I'll try to call <code>fun1</code> with parameter of other type - I'll get an error:</p>
  
  <pre><code>public fun2() {
    this.fun1([1, 2, 3]); // TS2345: Argument of type 'number[]' is not assignable to parameter of type 'number'
  }
  </code></pre>
  
  <p><strong>THE PROBLEM</strong></p>
  
  <p>Type checking works well if I can control the arguments in my files.</p>
  
  <p>But maybe <code>fun1</code> is called with some parameters which I get from backend.</p>
  
  <p>Typescript doesn't workin in runtime, so it won't show any errors, the code of <code>fun1</code> would just run with <code>[1, 2, 3]</code>.</p>
  
  <p>-- edited --</p>
  
  <p>Backend response is not the only source of problem. Sometimes a library can change type of your data and you might not know about it. An example would be using Reactive Forms with a control which should be a number - it's converted to string when you edit the number.</p>
  
  <p><strong>QUESTION</strong></p>
  
  <p>Is there some common way to handle type checking in runtime?</p>
  
  <p>I thought about something like:</p>
  
  <pre><code>public fun1(aaa: number) {
    if (typeof aaa !== 'number') {
      console.warn('wrong type');
    } else {
      console.log(aaa);
    }
  }
  </code></pre>
  
  <p>, but WebStorm then tells me <code>typeof check is always false: 'aaa' always has type 'number'</code>.</p>
  
  <p>Also putting something like this at the top of every function seems like adding a lot of unnecessary code.</p>
  
  <p>Does someone have a good solution for this?</p>