skip to content

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#

TopicPages
Setupinstallation · tsconfig
Type systemtypes vs interfaces · generics · utility types
Narrowingnarrowing · type guards · mapped & conditional types
Importstype-only imports
Advancedenums · decorators
Troubleshootingcommon errors
  1. Installation — install TypeScript globally or per-project with npm/pnpm
  2. tsconfig — understand strict, target, module, paths, and lib
  3. Types vs interfaces — when to use each and the key differences
  4. Generics — write reusable, type-safe functions and classes
  5. Utility typesPartial, Required, Pick, Omit, Record, ReturnType, and more
  6. Narrowing and type guards — runtime checks that refine types
  7. Mapped & conditional types — meta-programming at the type level
  8. Type-only importsimport type and its effect on output
  9. Enums — numeric vs string enums, and when to use const enums or plain objects instead
  10. Decorators — stage 3 decorators and experimentalDecorators legacy mode
  11. Common errors — TS2345, TS2322, TS2339, and the rest explained with fixes

[!TIP] Enable strict: true in your tsconfig.json from the start of every project. It catches far more bugs than the default loose settings and is much harder to add later.