0Pricing
TypeScript Academy · Lesson

The Result Pattern: Ok and Err

Return errors as values instead of throwing.

Welcome

The Result pattern returns errors as values, enabling type-safe error handling without try/catch.

Result Type

Define a generic Result type with Ok and Err variants.
type Ok<T> = { ok: true; value: T };
type Err<E = Error> = { ok: false; error: E };
type Result<T, E = Error> = Ok<T> | Err<E>;

All lessons in this course

  1. Typed Error Classes and Hierarchies
  2. The Result Pattern: Ok and Err
  3. Narrowing Caught Errors (unknown vs Error)
  4. Error Handling in Async TypeScript Code
← Back to TypeScript Academy