How to generate type checking in JavaScript at run time?
<p>With TypeScript or Facebook's Flow(type) I can statically type variables like</p>

<pre><code>function add (x: integer, y: integer) { ... }
</code></pre>

<p>Both TypeScript and Flow catch any illegal invocation such as <code>add('1',0)</code> at <strong>compile time</strong>. </p>

<p>However, when the library is compiled and exported, the types are gone. That means, the library consumer using that function gets no errors, that may potentially lead to hard-to-debug problems.</p>

<p>Is there any way to auto-generate additional code that would throw exactly the same errors at run time? </p>

<p>I can surely manually place guards every time a typecheck is expected but that feels boring and repetitive.</p>