Utilizing either TypeScript or Facebook's Flow (type), I am empowered to statically assign types to variables like this:
function add (x: integer, y: integer) { ... }
Both TypeScript and Flow are able to identify and prevent incorrect invocations such as add('1',0)
during compile time.
Nevertheless, once the library is compiled and exported, the types vanish. This means that the consumer of the library who uses that function will not receive any errors, potentially leading to complex debugging issues.
Is there a method to automatically generate additional code that would produce the same errors at runtime?
I could certainly manually insert guards each time a typecheck is needed, but that seems monotonous and redundant.