Skip to content
One-time payment9h 30m · 54 lessons

TypeScript in Depth

The route

  1. Inference is the point

    Letting the compiler do the work, and what an annotation is really for.

    You board here
    95 min
  2. Narrowing and the discriminated union

    Modelling states so the impossible ones will not compile.

    95 min
  3. Generics that read well

    Type parameters and constraints, and knowing when a generic is overkill.

    95 min
  4. The type-level toolkit

    Conditional and mapped types, keyof and template literals — used sparingly, on purpose.

    95 min
  5. Types at the boundary

    Validating what arrives from an API, and where `unknown` beats `any`.

    95 min
  6. Configuring a real codebase

    The strict flags, module resolution, and living with third-party types.

    95 min

A look at the teaching

Stop 2 · Narrowing and the discriminated unionSample excerpt

Make the impossible state fail to compile.

// Flags let you express nonsense — loading AND an error AND data:
type Bad = { loading: boolean; error?: string; data?: Course };

// A discriminated union cannot:
type State =
  | { status: "loading" }
  | { status: "error"; message: string }
  | { status: "ready"; data: Course };

function render(s: State) {
  if (s.status === "error") return s.message;    // narrowed
  if (s.status === "ready") return s.data.title; // narrowed
  return "Loading…";
}

The compiler now refuses the states you would otherwise have to remember not to create. That is worth more than any clever generic you will ever write.

Who is driving

PH
Péter Halász
Staff engineer

Péter teaches the way a good colleague explains things at a whiteboard — no jargon for its own sake, and nothing hidden behind “as you can see”.

Placeholder profile