ResultAsync
ResultAsync<T, E> is a thenable wrapper around Promise<Result<T, E>>; await returns the Result, not the inner T.
await
await resultAsync: Result<T, E>
Await a ResultAsync when you need to inspect or match its concrete Result.
okAsync / errAsync
okAsync<T, E = never>(value: T): ResultAsync<T, E> / errAsync<T = never, E = unknown>(error: E): ResultAsync<T, E>
Use these helpers when an asynchronous chain already has a success or failure value.
fromPromise
fromPromise<T, E>(promise: PromiseLike<T>, errorFn: (error: unknown) => E): ResultAsync<T, E>
fromPromise maps a rejected promise to Err; use fromAsyncThrowable when invoking the function could also throw synchronously.
fromSafePromise
fromSafePromise<T, E = never>(promise: PromiseLike<T>): ResultAsync<T, E>
Only use fromSafePromise for a promise known never to reject.
fromAsyncThrowable
fromAsyncThrowable<A extends readonly any[], R, E>(fn: (...args: A) => Promise<R>, errorFn?: (error: unknown) => E): (...args: A) => ResultAsync<R, E>
fromAsyncThrowable catches both synchronous throws during invocation and promise rejections.
andThen
andThen<U, F>(f: (value: T) => Result<U, F> | ResultAsync<U, F>): ResultAsync<U, E | F>
andThen accepts either a synchronous Result or another ResultAsync and skips the callback on Err.
map
map<A>(f: (value: T) => A | Promise<A>): ResultAsync<A, E>
map accepts a synchronous or asynchronous transform and leaves an Err untouched.
mapErr
mapErr<U>(f: (error: E) => U | Promise<U>): ResultAsync<T, U>
mapErr transforms an Err value and leaves an Ok untouched.
andCheck
andCheck<F>(f: (value: T) => Result<unknown, F> | ResultAsync<unknown, F>): ResultAsync<T, E | F>
andCheck runs a synchronous or asynchronous check while preserving the original Ok value.
orElse
orElse<U, F>(f: (error: E) => Result<U, F> | ResultAsync<U, F>): ResultAsync<T | U, F>
orElse recovers an Err with a synchronous or asynchronous fallback result.
unwrapOr
unwrapOr<A>(fallback: A): Promise<T | A>
unwrapOr resolves to the Ok value or the fallback when the result is an Err.
match
match<A, B = A>(ok: (value: T) => A, err: (error: E) => B): Promise<A | B>
match handles both variants and resolves to the selected callback's value.
then
then<A, B>(success?: (result: Result<T, E>) => A | PromiseLike<A>, failure?: (reason: unknown) => B | PromiseLike<B>): PromiseLike<A | B>
.then receives the resolved Result, which lets ResultAsync interoperate with promise-based APIs.