function foo(x) {

if (x < 2) {

return 42;

}

return "What are the return types of foo?";

}

The static definition of foo() does not hold any information about the parameters with which foo is called. In this simple case, we can deduct the return types, number and string . For more complex cases that is often impossible, though. But at runtime, it is clear with which types foo is being called. Runtime type information collects exactly this information.

Type profiling is implemented in V8 and can be used via the V8 inspector protocol. If you get Node.js with the newest V8, you can test it yourself. In a few weeks a newer V8 will land in Node and type profile will be available in regular Node releases.

One of the intended use cases is to auto-generate JSDoc, TypeScript, or Flow annotations. As type profiling is available via Node’s inspector, you can build your own tools with it to fit your needs. Here’s a demo to show some basic usage.

I look forward to all the tools the community will come up with that use type profile.

I look forward to all the tools the community will come up with that use type profile. I’m sure there are many use cases that I haven’t even considered yet. If you are already working on a prototype, please share!