TypeScript

TypeScript Foundations

Add a type system to JavaScript: catch mistakes while you write, and model data so wrong states cannot be represented.

intermediate12 lessons5 modules5h total

Helpful before you begin (optional -- you can start this course now): JavaScript Fundamentals

Who it's for

Developers comfortable with JavaScript who keep hitting bugs that a type system would have caught, and anyone joining a codebase that already uses TypeScript.

What you'll be able to do

  • Annotate variables, functions, arrays, and objects so the compiler checks your intent
  • Model data with interfaces, unions, and literal types instead of loose strings
  • Narrow a union safely and handle values that might be null or undefined
  • Write reusable generic functions and apply built-in utility types

Not started — 12 lessons, no account required.

Start this course

Practice this course →Add to a study plan →Interview questions

From JavaScript to TypeScript

Why a type system pays for itself, and the syntax you will use constantly.

  1. Why Types? From JavaScript to TypeScript

    What a type system buys you, and how TypeScript catches a bug that JavaScript happily runs.

    18 min
  2. Inference and the Primitive Types

    Let the compiler work out types for you, and learn the handful of primitives you will annotate by hand.

    20 min

Describing data

Typing the two shapes almost all real data takes, then naming them.

  1. Typing Arrays and Objects

    Describe collections and structured values, the two shapes almost all data takes.

    22 min
  2. Interfaces and Type Aliases

    Give a shape a name so it can be reused, extended, and referred to in one place.

    22 min

Handling variation and absence

Values that could be one of several types, or missing entirely.

  1. Union Types and Narrowing

    Say a value may be one of several types, then prove which one it is before using it.

    24 min
  2. Optional Fields and Nullability

    Model values that might be missing, and let the compiler force you to handle that case.

    22 min

Reusable types

Typing behaviour, then writing types that work for many shapes at once.

  1. Typing Functions

    Annotate parameters, returns, optional and default arguments, and functions passed as values.

    22 min
  2. Generics

    Write one function or type that works for many types without giving up checking.

    26 min
  3. Utility Types

    Derive new types from existing ones with Partial, Pick, Omit, Record, and Readonly.

    22 min

Precision and untrusted data

Narrowing types to exact values, and proving the shape of data you did not create.

  1. Literal Types and const Assertions

    Constrain a value to an exact set, and stop TypeScript widening the types you wanted narrow.

    20 min
  2. unknown, Type Guards, and Safe Assertions

    Handle data whose shape you cannot trust, and learn why `as` is the escape hatch of last resort.

    24 min
  3. Modelling a Domain So Wrong States Cannot Exist

    Bring the course together: use discriminated unions to make impossible states unrepresentable.

    26 min

Where to go next

Optional -- these build well on what you just learned, but any course can come next.