ResultAsync<T, E> is a PromiseLike<Result<T, E>>. You can await or .then() it directly to get a synchronous Result<T, E>, or chain methods on it without ever leaving the async context. Nearly Every method that exists on Result has an equivalent on ResultAsync, and 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.
chas.errAsync(error)
Wraps an error or Promise<E> in a ResultAsync that resolves to Err.
chas.fromPromise(promise, mapErr?)
Wraps a native Promise in a ResultAsync. Resolves to Ok on fulfillment and Err on rejection.
Maps the rejection reason to your error type. When omitted, the error is typed as
unknown.ResultAsync.fromResult(syncResult)
Lifts a synchronous Result into ResultAsync.
ResultAsync.fromSafePromise(promise)
Wraps a promise that is guaranteed not to reject. No mapErr is needed.
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.
.mapErr(fn)
Transforms the Err error. Ok passes through unchanged.
.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.
.orElse(fn)
Recovers from an Err by calling fn with the error. Ok passes through unchanged.
.tap(fn)
Runs a side effect when Ok. Returns the original result unchanged.
.tapErr(fn)
Runs a side effect when Err. Returns the original result unchanged.
.match({ ok, err })
Exhaustively handles both branches and resolves to a plain value.
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.
.unwrapOr(defaultValue)
Returns a Promise that resolves to the Ok value, or defaultValue if Err.
.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.
.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.
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.
Side-effect function called when the tag matches.