Skip to content

Type Erasure

In one line

Type erasure is the process by which the TypeScript compiler removes all type annotations, interfaces, and type aliases, producing plain JavaScript with no type information.

In simple words

Type erasure means all TypeScript type information is removed when compiling to JavaScript. Type annotations, interfaces, type aliases, generics, and utility types are all erased — the output is plain JavaScript.

This is why TypeScript types cannot be checked at runtime. If you need runtime type information, you must use enums (which compile to objects), classes (which compile to JS classes), or runtime validation libraries like zod or io-ts.

Type erasure is a fundamental design decision: it keeps the JavaScript output clean and performant, and ensures TypeScript is a strict superset of JavaScript. The tradeoff is that types are a compile-time-only concept.

Example

typescript
// TypeScript input
let x: number = 5;
interface User { name: string; }

// JavaScript output (after erasure)
let x = 5;
// interface User is gone

All type annotations and interfaces are removed in the JavaScript output.

Related terms

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary