Skip to main content

Overview

Extracts the Ok value from a ResultAsync, or returns the provided default value if it’s an Err. Returns a Promise of the value.

Signature

A
required
The default value to return if the ResultAsync is an Err
Returns: Promise<T | A> - A Promise resolving to the Ok value or the default

Usage

Basic usage

Configuration with defaults

API responses

Chaining with transformations

Key characteristics

Use unwrapOr at the end of a Result chain when you want to exit the Result context and always get a value.
  • Always succeeds: Never throws, always returns a value
  • Type safety: Return type is union of Ok and default types
  • Returns Promise: Requires await or .then() to access the value

When to use

  • At application boundaries where you need concrete values
  • When a sensible default exists for error cases
  • Converting Result-based code to traditional async code
The default value is evaluated eagerly. If computing it is expensive, consider using match() or orElse() instead.

match

Handle both cases with callbacks

orElse

Compute default based on the error