ResultAsync<T, E> is a PromiseLike<Result<T, E>>. You can await it directly to get a synchronous Result<T, E>, or chain methods on it without ever leaving the async context. Every method that exists on Result has an equivalent on ResultAsync — each returns another ResultAsync so chains stay fluent.
Creating a ResultAsync
chas.okAsync(value)
Wraps a value or Promise<T> in a ResultAsync that resolves to Ok.
The success value or promise to wrap.
Resolves to
Ok(value).chas.errAsync(error)
Wraps an error or Promise<E> in a ResultAsync that resolves to Err.
The error value or promise to wrap.
Resolves to
Err(error).chas.fromPromise(promise, mapErr?)
Wraps a native Promise in a ResultAsync. Resolves to Ok on fulfillment and Err on rejection.
The promise to wrap.
Maps the rejection reason to your error type. When omitted, the error is typed as
unknown.A
ResultAsync wrapping the promise outcome.ResultAsync.fromResult(syncResult)
Lifts a synchronous Result into ResultAsync.
The synchronous result to wrap.
A
ResultAsync that immediately resolves to the provided result.ResultAsync.fromSafePromise(promise)
Wraps a promise that is guaranteed not to reject. No mapErr is needed.
A promise that will not reject.
Resolves to
Ok(value).Instance methods
All methods below return aResultAsync, so you can chain them without await until you need the final value.
.map(fn)
Transforms the Ok value. Err passes through unchanged.
Function applied to the
Ok value. May be async.Ok(fn(value)) or the original Err..mapErr(fn)
Transforms the Err error. Ok passes through unchanged.
Function applied to the
Err error. May be async.The original
Ok or Err(fn(error))..andThen(fn)
Chains another Result- or ResultAsync-returning function. Calls fn with the Ok value, or short-circuits on Err.
Function returning a new result. May return sync or async.
The chained result, or the original
Err..orElse(fn)
Recovers from an Err by calling fn with the error. Ok passes through unchanged.
Recovery function returning a new result.
The original
Ok, or the recovery result..tap(fn)
Runs a side effect when Ok. Returns the original result unchanged.
Side-effect function. May be async.
The original result, unmodified.
.tapErr(fn)
Runs a side effect when Err. Returns the original result unchanged.
Side-effect function. May be async.
The original result, unmodified.
.match({ ok, err })
Exhaustively handles both branches and resolves to a plain value.
Handler called when the result is
Ok.Handler called when the result is
Err.A standard
Promise (not a ResultAsync) resolving to the matched handler’s return value..unwrap()
Returns a Promise that resolves to the Ok value, or throws the Err error.
Resolves to the
Ok value..unwrapOr(defaultValue)
Returns a Promise that resolves to the Ok value, or defaultValue if Err.
Fallback value returned when the result is
Err.Resolves to the
Ok value or the default..pipe(fn1, fn2, ...)
Passes the ResultAsync through a sequence of functions, identical in behaviour to Result#pipe.
.context(ctx)
Attaches a debug label or metadata object to the error when Err. No-op when Ok.
A description string or metadata object for the current step.
The same result with context prepended to
error._context (if Err)..catchTag(target, handler)
Catches a specific tagged error variant by _tag or error factory, and removes it from the error union. Unmatched tags pass through unchanged.
The
_tag string to match, or an error factory.Recovery function.
A result with the matched tag removed from the error union.
.tapTag(target, handler)
Runs a side effect for a specific tagged error. The original result is returned unchanged.
The
_tag string to match, or an error factory.Side-effect function called when the tag matches.
The original result, unmodified.