← Lessons

quiz vs the machine

Gold1470

Frontend

Type Checking with TypeScript

A static type checker proves shapes line up before code runs, catching whole classes of bugs early.

5 min read · core · beat Gold to climb

Catching errors before runtime

TypeScript adds static types to JavaScript and checks them at build time. It analyzes how values flow through your code and reports when a shape does not line up, such as reading a property that might not exist. This catches a whole class of bugs before the code ever runs.

  • Types describe the shape of values, props, and function results.
  • The checker verifies callers and callees agree on those shapes.
  • Errors surface in the editor as you type, not in production.

Types erase at build

Types exist only during checking and compilation. They are erased before the code runs, so they add no runtime cost and cannot enforce anything at runtime by themselves. That is why data crossing a boundary, like a network response, still needs validation.

  • Compile time: the checker proves internal consistency.
  • Runtime: external data is unchecked unless you validate it.
  • Stronger types document intent and enable safer refactors.

A precise type acts like a contract: change a function signature and every mismatched caller lights up immediately. The discipline pays off most on large codebases where invisible assumptions otherwise rot silently.

Key idea

TypeScript checks value shapes at build time to catch bugs early, but types erase at runtime so boundary data still needs validation.

Check yourself

Answer to earn rating on the learn ladder.

1. When does TypeScript catch a shape mismatch?

2. Why must network response data still be validated at runtime?