Free through lesson 3

TypeScript for Beginners

From type annotations and inference through union types, narrowing, generics, classes and utility types, all the way to async code and the DOM. Fifty lessons that take you to the point where you find your mistakes before you run anything. Every piece of code and every tsc output shown was produced by actually running it.

Curriculum

The 50 lessons are grouped into seven chapters. Working through them in order is the best way, but you are welcome to dip into whatever interests you. Note: the in-page editor simply strips the types and runs the result, so real type errors are shown as tsc output instead.

Chapter 1 — Starting with TypeScript (lessons 1–6)

You get a feel for what TypeScript takes off your hands by writing the same logic side by side with JavaScript. Setting up, tsconfig.json, type annotations and inference, and how to get by without any.

Chapter 2 — Composing types (lessons 7–16)

Arrays, objects, union and intersection types, and naming types with type and interface. You go far enough to narrow a union type, which otherwise only lets you use what its members have in common.

7

Arrays and tuples

number[] and Array<number> mean the same thing. Tuples fix a type per position, and how far readonly protects you.

🔒 Basic
8

Object types and structural typing

Writing out property names and their types. Structural typing accepts any matching shape, and excess property checks only fire on object literals.

🔒 Basic
9

Type aliases (type)

Naming a type with type so you can reuse it. It works on more than objects, but it cannot be used as a value.

🔒 Basic
10

Choosing between interface and type

Either can describe an object type. Declaration merging is interface-only, and some types can only be written with type.

🔒 Basic
11

Optional properties and readonly

A ? makes a property omittable, but brings undefined with it. readonly protects one level and no further.

🔒 Basic
12

Union types

A type joined with a pipe only lets you use what its members share. A tagged union with a discriminant turns state into a type.

🔒 Basic
13

Literal types and as const

Making a value itself a type. Why let and object properties widen to string, and how as const pins them.

🔒 Basic
14

Intersection types (&)

Extracting common properties and combining them. Mixing incompatible types gives you never.

🔒 Basic
15

Narrowing

Confirming what something is right now with typeof, in and instanceof. Including the situations where narrowing is lost.

🔒 Basic
16

enum versus union types

An enum emits code when compiled, so node file.ts will not run it. Comparing it against as const and a union type.

🔒 Basic

Chapter 3 — Functions and types (lessons 17–23)

Parameters and return values, callbacks and overloads — a full pass over the types around functions. Type guard and assertion functions make your own checks narrow types too.

Chapter 4 — Generics (lessons 24–30)

You write functions that take a type the way they take an argument and hand that same type back. Combining keyof, typeof and indexed access types, you finish by building a type-safe storage helper.

Chapter 5 — Classes and type declarations (lessons 31–36)

Property declarations, access modifiers, inheritance and implements — the types around classes. Then .d.ts files and @types, for using untyped JavaScript safely.

Chapter 6 — Utility types and type operations (lessons 37–44)

You use the built-in types — Partial, Pick, Omit, Record — to derive purpose-built types from a single source type. The second half is how they are made: mapped types, conditional types, infer and satisfies.

Chapter 7 — Putting it into practice (lessons 45–50)

Modules, async code, validating fetch responses, error handling and the DOM. You finish by assembling a to-do app and seeing what happens when you change a single word in a type definition.

Once you have finished all 50 lessons, move on to the framework side with Next.js. Membership unlocks every course.