Skip to main content

Overview

Type guard method that checks if a Result is an Ok variant. Returns true if the Result contains a success value.

Signature

Returns: boolean - true if the Result is Ok, false if it’s Err

Usage

Basic type checking

Type narrowing

Early returns

Filtering arrays

Type guard behavior

isOk() is a TypeScript type guard. After checking isOk(), TypeScript automatically narrows the type to Ok<T, E>, giving you access to .value.

Comparison with other patterns

isOk vs match

isOk vs unwrapOr

When to use

  • ✅ When you need different logic for success vs failure
  • ✅ When integrating with existing imperative code
  • ✅ When you need to access both .value and .error in different branches
  • ❌ When you just need the value → use unwrapOr() instead
  • ❌ When transforming results → use map() or andThen() instead

isErr

Check if Result is an Err variant

match

Pattern match on both variants