Skip to main content

Overview

Maps a ResultAsync<T, E> to ResultAsync<T, F> by applying a function to the contained Err value. The Ok value is left untouched.

Signature

(e: E) => U | Promise<U>
required
Function to transform the Err value. Can return either a value or a Promise.
Returns: ResultAsync<T, U> - A new ResultAsync with the transformed error

Usage

Convert error types

Async error mapping

Add context to errors

Key characteristics

  • Short-circuits on Ok: If the ResultAsync is Ok, mapErr is not executed
  • Type transformation: Allows changing the error type in the Result
  • Async support: Can handle both sync and async error transformation functions
Use mapErr to normalize error types across different operations, making error handling consistent.

map

Transform the Ok value

orElse

Recover from errors