TypeScript
A typed superset of JavaScript that compiles to plain JavaScript, adding static types and modern features.
Created by Microsoft (Anders Hejlsberg)
TypeScript is a typed superset of JavaScript developed by Microsoft. Every valid JavaScript program is also valid TypeScript, but TypeScript adds optional static types, classes, interfaces, and other features that make large-scale JavaScript development more manageable.
History & Origins
TypeScript was created by Anders Hejlsberg, the legendary language designer behind Turbo Pascal, Delphi, and C#. By 2010, Microsoft saw that JavaScript was becoming the dominant language for web development, but large JavaScript codebases were difficult to maintain.
Google had faced similar challenges and created Closure Compiler with type annotations in comments. Google also proposed adding optional types to JavaScript itself (the abandoned “Traceur” project). Microsoft took a different approach: create a new language that compiles to JavaScript.
The Problem TypeScript Solves
JavaScript, despite its ubiquity, has significant challenges at scale:
- No static types: Errors caught at runtime, not compile time
- Weak tooling: Limited autocomplete, refactoring, and navigation
- Documentation burden: JSDoc comments are optional and often wrong
- Refactoring risk: Renaming a function might break code anywhere
TypeScript addresses these directly:
- Static type checking: Catch errors before running code
- Rich IDE support: Autocomplete, go-to-definition, refactoring
- Self-documenting: Types serve as verified documentation
- Safe refactoring: The compiler finds all affected code
Rise to Prominence
TypeScript grew slowly at first. Many JavaScript developers were skeptical of types and Microsoft technology. The turning point came in 2016-2017:
- Angular 2 (2016): Google chose TypeScript for Angular, not their own Dart
- VS Code (2015-2016): Microsoft’s hit editor, written in TypeScript, proved the concept
- React community adoption: DefinitelyTyped provided types for React
- Vue 3 (2020): Vue.js rewrote their core in TypeScript
By 2024, TypeScript is the dominant choice for new JavaScript projects:
- Most major frameworks have TypeScript support
- npm packages commonly ship with type definitions
- Many companies require TypeScript for new projects
Why TypeScript Succeeded
- Gradual adoption: Add types incrementally, file by file
- JavaScript compatibility: All JS is valid TS; use existing code
- Excellent tooling: Outstanding IDE support from day one
- Open source: MIT licensed, community-driven development
- Anders Hejlsberg: Credibility from the C# creator
- Structural typing: More flexible than Java/C# nominal typing
TypeScript’s Type System
TypeScript uses structural typing (duck typing with static checks):
| |
Key type system features:
- Union types:
string | number - Intersection types:
A & B - Generics:
Array<T>,Promise<T> - Mapped types: Transform types programmatically
- Conditional types:
T extends U ? X : Y - Template literal types: Type-safe string manipulation
Modern TypeScript
TypeScript 5.x brought significant improvements:
- Decorators: Stage 3 ECMAScript decorators
- const type parameters:
<const T> - Performance: Faster builds and type checking
- Module resolution: Better ESM and bundler support
The language continues evolving to support new JavaScript features while adding type system capabilities.
TypeScript vs. JavaScript
| Feature | TypeScript | JavaScript |
|---|---|---|
| Type checking | Static, compile-time | Dynamic, runtime |
| IDE support | Excellent autocomplete/refactoring | Limited without JSDoc |
| Learning curve | Steeper initially | Lower barrier to entry |
| Build step | Required (tsc) | Optional |
| Runtime | Compiles to JavaScript | Runs directly |
| Null safety | Strict null checks available | No built-in checks |
TypeScript compiles away to JavaScript—there’s no TypeScript runtime. This means:
- No runtime overhead
- Runs anywhere JavaScript runs
- Can target any JavaScript version (ES5, ES6, ESNext)
The TypeScript Ecosystem
TypeScript has a rich ecosystem:
- DefinitelyTyped: Community-maintained type definitions for JS libraries
- ts-node: Run TypeScript directly without pre-compilation
- tsx: Modern, fast TypeScript execution
- tsc: The official TypeScript compiler
- ESLint: TypeScript-aware linting with @typescript-eslint
Most modern tools have first-class TypeScript support: Vite, esbuild, SWC, Bun, and Deno all handle TypeScript natively.
The TypeScript Community
TypeScript has a welcoming community focused on practical solutions:
- GitHub: Active development and issue discussion
- TypeScript Discord: Community help and discussion
- TS Conf: Annual conference
- Weekly releases: Rapid iteration on features
Microsoft maintains TypeScript as a genuinely open source project, accepting community contributions and engaging with feedback through the RFC process.
Timeline
Notable Uses & Legacy
Visual Studio Code
Microsoft's popular editor is written entirely in TypeScript, showcasing large-scale TypeScript development.
Angular
Google's web framework is built with and requires TypeScript, driving enterprise adoption.
Deno
Ryan Dahl's modern JavaScript runtime has first-class TypeScript support without compilation.
Slack Desktop
Slack migrated their Electron-based desktop app to TypeScript for improved maintainability.
Airbnb
Adopted TypeScript across their frontend codebases for type safety at scale.
Stripe
Uses TypeScript extensively for their dashboard and developer tools.
Language Influence
Influenced By
Influenced
Running Today
Run examples using the official Docker image:
docker pull node:22-alpineExample usage:
docker run --rm -v $(pwd):/app -w /app node:22-alpine sh -c 'npx -y ts-node hello.ts'