Live data from Hacker News

Runtime type information for JavaScript

medium.com

1–10 of 16 posts

Re: Runtime type information for JavaScript

#2
Cool! I've been wanting something like this for a long time for IDE-suggested type annotations. "From test execution it looks like parameters x and y are always numbers. Add type annotations automatically?"

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."

Re: Runtime type information for JavaScript

#3
post #2

Cool! I've been wanting something like this for a long time for IDE-suggested type annotations. "From test execution it looks like parameters x and y are always numbers. Add type annotations automatically?" 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."

[deleted]

Re: Runtime type information for JavaScript

#4
I've recently worked on something similar, which uses dynamic analysis to be able to collect type informations and many other data which is only available at runtime.

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/

Re: Runtime type information for JavaScript

#6
post #2

Cool! I've been wanting something like this for a long time for IDE-suggested type annotations. "From test execution it looks like parameters x and y are always numbers. Add type annotations automatically?" 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."

The JavaScript intellisense engine of previous versions of Visual Studio used to instrument a sandboxed JS engine in order to extract the shape of objects and methods used in the code, so it also worked when unusual idioms for structuring code were used. Recent versions use instead the TypeSript compiler, with support for plain JavaScript and flow analysis.

Re: Runtime type information for JavaScript

#7
The code has to be executed for getting the type information (hence the runtime).

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.

Re: Runtime type information for JavaScript

#8
post #2

Cool! I've been wanting something like this for a long time for IDE-suggested type annotations. "From test execution it looks like parameters x and y are always numbers. Add type annotations automatically?" 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."

That sounds useful! Maybe helpful for you is that YouCompleteMe for Vim is able to offer some type inference based on usage.

Re: Runtime type information for JavaScript

#9
post #4

I've recently worked on something similar, which uses dynamic analysis to be able to collect type informations and many other data which is only available at runtime. 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…

Wow, That's some pretty interesting stuff you have there.
Post reply on HN