Runtime type information for JavaScript
medium.com
medium.com
Runtime type checking: https://maierfelix.github.io/Iroh/examples/type-checking/
JavaScript -> Flow conversion: https://maierfelix.github.io/Iroh/examples/auto-flow-types/
It's also possible to turn the runtime control-flow of running JavaScript into a playable game: https://maierfelix.github.io/src2game/
INPUT >>> function add(f, b) { return f(b); };
let a = add(function(x) {return x + 1}, 3);
OUTPUT >>> function add(f: function, b: number): number { return f(b); };
let a: number = add(function(x: number): number {return x + 1}, 3);
and I noticed that the flow type annotations are added to the call site, rather than on the argument f in the definition of add. Are all the types that you generate first order?
The motivation for dynamic checking was often because many JavaScript programs couldn't be given any useful static types. With the great work on Flow and TypeScript I'm starting to become convinced that we'll just be able to statically check most JavaScript programs in the future and get decent types out.
I like this quote: “Dynamic typing: The belief that you can’t explain to a computer why your code works, but you can keep track of it all in your head.”
I don't get it personally, when you've got decent type inference the number of type annotations should be minimal and compile-time errors mean things that would cause a runtime crash anyway.
Or a linter could give optimization recommendations: "Warning: Function deoptimized at runtime because in 2% of calls to this function parameter x is an object."
It is less powerful than inferring types, and won't help I think from an IDE perspective, except in the edge case of refining types that are too broad; but it will be based on one execution path.