DevTools Logo
All posts

TypeScript to JavaScript: What Type Erasure Actually Removes

August 10, 2026 · DevTools

typescript
javascript
type-erasure
conversion
transpiler

TypeScript types exist to be erased. The compiler's job at build time is to check them, then strip them so the plain JavaScript underneath can run in any engine. Understanding exactly what a converter removes is understanding the whole model.

Erased: variable and parameter annotations (const n: number), return types, generic type parameters on functions and classes, interface and type alias declarations, type-only imports, and the access modifiers public, private, and protected. An as or satisfies assertion is a compile-time claim, so it goes too. An enum — enum Color { Red, Green } — has no JavaScript equivalent, so it is rewritten as a plain const object.

Preserved: everything with runtime meaning. Strings, template literals, comments, and regex literals are masked before rewriting, so a docstring that mentions number is never touched. Because the types vanish independently of the values, the output is usually the minimal honest JavaScript — which is also why it reads so cleanly.

The boundary is the warning that follows "eraser": compile-time and runtime-only features. Parameter properties, decorators, and const-enum inlining change emitted runtime behavior, and an enum rewritten as a const object loses numeric reverse-mapping. For ordinary annotated code the output is exact; for anything unusual, glance over the result. The TypeScript to JavaScript Converter is the fastest way to see the erasure on your own file — paste the module, read the JavaScript that was always underneath it.