Field Guide · language

Also known as: TypeScript, TS

TypeScript is a statically typed superset of JavaScript: it adds an optional type system on top of JavaScript and compiles down to plain JavaScript that runs anywhere JavaScript does.1

.ts source+ types tsc type check+ erase types .js output runs
TypeScript type-checks at build time, then erases the types and emits plain JavaScript.

Overview

TypeScript exists to fix JavaScript’s biggest weakness — its loose dynamic typing. You annotate code with types, the tsc compiler checks them at build time, and then the types are erased: the emitted output is ordinary JavaScript with no runtime type system of its own.2 Memory and execution are still handled by the JavaScript runtime, so TypeScript adds safety without changing how the program runs.

Strengths and trade-offs

The static type layer catches a large class of bugs before the code runs, improves editor tooling and autocompletion, and makes large codebases far easier to refactor and maintain. The costs are a build/compile step that plain JavaScript does not need, time spent writing and maintaining type annotations, and the fact that types are only checked at compile time — they cannot guarantee anything about untyped data arriving at runtime, so error handling at boundaries still matters. The gradual, structural design (its lead designer also created C#) lets teams adopt it incrementally.

Where it’s used

TypeScript has become the default for serious front-end frameworks and Node.js backends, and for any JavaScript codebase large enough that loose typing becomes a liability. Because it compiles to plain JavaScript, it runs everywhere JavaScript runs and interoperates freely with existing JS libraries.

Sources

  1. TypeScript — Wikipedia, for history and design background. 

  2. The TypeScript programming language — official site, documentation, and the tsc compiler and type system. 

See also