0Pricing
TypeScript Academy · Lesson

Option and Maybe Types

Model the presence or absence of a value explicitly.

Modeling Absence

Sometimes a value may simply be absent, with no error to report. An Option (also called Maybe) models presence or absence explicitly, an alternative to null and undefined.

Defining Option

Option is a discriminated union with a some tag. When some is true there is a value; when false there is nothing.

type Option<T> =
  | { some: true; value: T }
  | { some: false };

All lessons in this course

  1. The Problem with Throwing Errors
  2. Modeling Result Types
  3. Option and Maybe Types
  4. Railway-Oriented Programming
← Back to TypeScript Academy