TypeScript
TypeScript

0: Introduction
1: Your first TypeScript program
2: Types
3: Typing functions
4: The editor helps you with type errors
5: Running TypeScript code
6: Valid types
7: Type aliases and interfaces
8: ▶︎ Union types
9: Typing arrays with generics
10: The DX of editing TypeScript
11: There's more...

[← back to the Valley]

TypeScript: Union types

Union types let us tell TypeScript a value can be of one type, or another type.

Example:

const run = (a: number | string) => {
  //...
}

In this case the parameter a can be either a string, or a number, but nothing else.

◀︎ Type aliases and interfaces
▶︎ Typing arrays with generics

Lessons in this unit:

0: Introduction
1: Your first TypeScript program
2: Types
3: Typing functions
4: The editor helps you with type errors
5: Running TypeScript code
6: Valid types
7: Type aliases and interfaces
8: ▶︎ Union types
9: Typing arrays with generics
10: The DX of editing TypeScript
11: There's more...

Join my AI Workshop!

The Web Development BOOTCAMP cohort starts in February 2026