by dynamite-ready · 4y ago · 0 comments
I’m curious about this, and runs counter to my understanding of typescript. Do you have any sources on this?
I’m googling a bit but not really finding anything.
Wrong. TS doesn’t bundle files. TS doesn’t produce code unless you target an earlier ES version than what you write, in which case there’s no way around it: native for-of loops and await/async will always be faster regardless of what you use to transpile it.
I think you’re confusing the tool with something else.
Non-const enums and namespaces are probably the only aspects of typescript that actually have any significance at runtime, but they get compiled into simple objects. The compiler output is very close to what you'd write by hand. Take a look at this compiler output here [1].
Unless you're constantly recreating enums and namespaces inside of a loop (which you'd never do in real life code), I can't imagine there'd be any performance penalty.
[1] https://www.typescriptlang.org/play?target=99#code/HYQwtgpgz...
Turning `export function a(){}` into `exports.a = function a(){}` hardly qualifies as generated code, much less "slower than hand-written"