TypeScript
27 cheat sheets
TypeScript#
TypeScript adds a static type layer on top of JavaScript that is erased at compile time. It ships as a compiler (tsc) and a language server that powers editor autocompletion across every major IDE.
What’s in this section#
| Topic | Pages |
|---|---|
| Setup | installation · tsconfig |
| Type system | types vs interfaces · generics · utility types |
| Narrowing | narrowing · type guards · mapped & conditional types |
| Imports | type-only imports |
| Advanced | enums · decorators |
| Troubleshooting | common errors |
Recommended reading order#
- Installation — install TypeScript globally or per-project with npm/pnpm
- tsconfig — understand
strict,target,module,paths, andlib - Types vs interfaces — when to use each and the key differences
- Generics — write reusable, type-safe functions and classes
- Utility types —
Partial,Required,Pick,Omit,Record,ReturnType, and more - Narrowing and type guards — runtime checks that refine types
- Mapped & conditional types — meta-programming at the type level
- Type-only imports —
import typeand its effect on output - Enums — numeric vs string enums, and when to use
constenums or plain objects instead - Decorators — stage 3 decorators and
experimentalDecoratorslegacy mode - Common errors — TS2345, TS2322, TS2339, and the rest explained with fixes
[!TIP] Enable
strict: truein yourtsconfig.jsonfrom the start of every project. It catches far more bugs than the default loose settings and is much harder to add later.
no sheets match the selected filters