TypeScript
A type system bolted onto JavaScript, and one of the most successful bets in language design.
- First released
- 2012
- Created by
- Anders Hejlsberg and colleagues, at Microsoft
- Typing
- Static, structural and gradual; erased at runtime
- File extensions
- .ts, .tsx, .d.ts
What it is for
TypeScript fills one specific gap: JavaScript codebases too large for anyone to hold in their head. It adds a static type system and takes nothing away, compiling to ordinary JavaScript with the types erased. Nothing survives to runtime, which is exactly why you can adopt it one file at a time.
The type system is structural rather than nominal, so what matters is an object's shape and not the name it was declared with. It also goes well past what most static languages offer: unions and intersections, literal types, conditional and mapped types, and inference good enough to type most code with no annotations at all. That expressiveness is not showing off. It has to describe JavaScript as people actually wrote it, including patterns no sane type system would have invited.
It is now the default for new front-end work of any size, and common on the server through Node and Deno. The honest limit is that the guarantees stop at the boundary. Anything arriving from a network call or a JSON file is typed by assertion, not by proof, so runtime validation is still your job.
Where it came from
Microsoft released TypeScript in October 2012, with Anders Hejlsberg leading the design, having previously built Turbo Pascal, Delphi and C#. The reception was skeptical. Compile-to-JavaScript languages were a crowded and unloved category at the time, and CoffeeScript was the fashionable one.
Tooling changed that. Editor support built on the same compiler gave JavaScript developers accurate autocomplete, rename and go-to-definition for the first time, and DefinitelyTyped supplied hand-written type definitions for libraries that shipped none. Angular adopting it in 2015 made it credible for large projects.
Adoption became near-universal over the following decade, to the point that shipping types with a library is table stakes. The language kept growing carefully: strict null checks, discriminated unions, template literal types, satisfies. Throughout it has held one rule that served it well. The emitted JavaScript is JavaScript, and the types never change what runs.
What it is like to type
TypeScript is JavaScript plus a second grammar of angle brackets and colons. Generics put < and > inside ordinary identifiers, annotations add a colon to most declarations, and union types turn the pipe from a rare keystroke into a common one. Of everything here, this is the hardest workout for the shifted symbol row.
82 steps across 5 tours, from the basics to complete programs.
The tours
- Types & annotationsThe type system as you meet it. 23 steps.
- GenericsType parameters, and then the part people skip: reading types rather than only writing them. 20 steps.
- Type-level programmingConditional types, mapped types, template literal types, and recursion. 12 steps.
- Classes & patternsWhere the types meet real code. 19 steps.
- Async & modulesEight steps on the boundary. 8 steps.