All topics / TypeScript From Zero

TypeScript From Zero

Learn TypeScript from nothing to genuinely advanced: install it and the basics — types, functions, interfaces, unions, generics, classes, and the build — then the deep half: the structural type system, utility and mapped types, conditional and template-literal types, and typing the real world. Mental-model-first, with honest explanations.

  1. Install & Your First Program — tsc, tsconfig, and the Compile Step TypeScript never runs directly — the tsc compiler checks your types and emits plain JavaScript that Node or the browser runs. Install it, write a typed program, watch the checker catch a bug, and meet tsconfig.
  2. Why Types & the Basic Types — What the Checker Buys You The concrete payoff of types — a silent NaN bug caught at edit-time — plus the primitives, inference (you annotate less than you think), arrays and tuples, and why unknown beats any.
  3. Functions & Annotations — Typing the Boundaries Functions are the contracts between parts of your program — the highest-value place for types. Parameter and return types, arrow functions, optional and default and rest parameters, and the void/never distinction.
  4. Objects, Interfaces & Type Aliases — Describing Shapes Real data is objects. Here's how to name an object's shape once with interface or type, reuse it everywhere, mark fields optional or readonly, extend shapes, and pick between interface and type without agonizing.
  5. Unions, Literals & Narrowing — One of Several Shapes Real values are often one of several possibilities. Union and literal types model that directly, then narrowing forces you to handle each case — peaking with discriminated unions and exhaustiveness checks the compiler enforces.
  6. Generics — Reusable Code That Keeps Its Types Generics let one function or type work over many types without throwing the types away like `any` does. Type parameters, multiple parameters, constraints with extends and keyof, and generic types, interfaces, and classes.
  7. Classes & OOP in TypeScript — Types on Objects With Behavior JavaScript already has classes; TypeScript adds a type layer — field types, visibility, and contracts. Learn typed fields, access modifiers, parameter properties, readonly, getters/setters, and implements vs abstract.
  8. Modules, tsconfig & the Build — Configuring the Compiler How TS shares code with ES modules and type-only imports, what tsconfig.json controls, the compiler options that actually matter, why strict mode is non-negotiable, and where tsc fits alongside a bundler.
  9. The Type System, Deep — Structural Typing & How Inference Works How TypeScript really decides if two types fit: structural (shape-based) typing, assignability, excess-property checks, literal widening, as const, and how inference flows from context.
  10. Utility & Mapped Types — Deriving Types From Types Stop hand-maintaining parallel types. Use keyof, indexed access, the built-in utility types, and mapped types to derive one type from another so they can never drift apart.
  11. Conditional & Template Literal Types — Types That Make Decisions Types can branch and pattern-match: conditional types are a type-level ternary, infer reaches inside a type, and template literal types build string types from patterns. Learn to read the magic and write the simple cases.
  12. Typing the Real World — Libraries, Declarations & Untyped Data The reality check: your code is type-safe, but libraries, the network, and JSON are not. How @types and .d.ts files work, why fetch and JSON.parse lie, what `as` really costs, and how runtime validation closes the gap.
  13. Where to Go Next — Putting TypeScript to Work You learned the durable, hard part — the type system itself. Here's the honest map of where to apply it: typed React, typed Node APIs, and the modern superpower of end-to-end type safety with tools like tRPC and Prisma.