TypeScript’s static types are erased at compile time, of course, and are not present at runtime. But I suspect that we get a performance benefit anyway. Hear me out.
If this assumption turns out to be wrong, V8 will back out of the predicted branch, and handle it correctly. But if the assumption is correct, we get a performance benefit. A hot path, so to speak.
My hypothesis is that the use of TypeScript by the developer makes correct predictions more likely.
By typing a function parameter as
number, we prevent ourselves from passing some other type to that function call. So V8’s type prediction turns out to be more accurate, more often, thanks to the discipline enforced at development time.