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.