With TypeScript or Facebook's Flow(type) I can statically type variables like
function add (x: integer, y: integer) { ... }
Both TypeScript and Flow catch any illegal invocation such as add('1',0)
at compile time.
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.
Is there any way to auto-generate additional code that would throw exactly the same errors at run time?
I can surely manually place guards every time a typecheck is expected but that feels boring and repetitive.
https://github.com/codemix/babel-plugin-typecheck does what you want.
There is also https://gcanti.github.io/flowcheck/ but it looks a bit abandoned.
I haven't personally used any of those libraries. It seems that they might cover less than 100% of Flow syntax.