Skip to main content
← TypeScript Lesson 1 / 4

Types Vanish at Runtime

Think of TypeScript as JavaScript with sticky notes about types. Before your code runs, the compiler reads the notes to catch mistakes — then peels every note off. What actually runs is plain JavaScript. The types are gone.

What you're looking at

The left is what you write; the right is what actually runs after tsc erases the types.

Try to use a type at runtime

What happens if you treat a type like a real value when the program runs? Flip this on to find out.

What you wrote (.ts)

const age: number = 30;

function greet(name: string): string {
  return "hi " + name;
}

type User = { id: number };

Type-space (checked, then erased)

  • : number — the annotation on age
  • : string — the parameter type of name
  • : string — the return type of greet
  • type User = { id: number } — a whole type declaration

Two worlds

Exists only while checking

  • : number
  • : string
  • : string
  • type User = { id: number }

Exists when the program runs

  • const age = 30
  • function greet(name)
  • "hi " + name

TypeScript adds a checking pass before the code runs and changes nothing about what runs. Types have zero runtime cost — and zero runtime existence.