ResultAsync allows you to work with asynchronous Results in a type safe way

ResultAsync<T,E> is a wrapper around Promise<Result<T,E>> which provides the same methods for chaining different Result and ResultAsync together as Result, while also chaining the asynchronous operations together using Promise.then.

ResultAsync is thenable (implements PromiseLike<T>) so can be used in most places that a Promise can, including with await.

Compatible with neverthrow

Type Parameters

  • T

    The type of the value contained in the ResultAsync for the success case

  • E

    The type of the error contained in the ResultAsync for the failure case

Hierarchy (View Summary)

Constructors

  • Type Parameters

    • T
    • E

    Parameters

    • res: Promise<Result<T, E>>

    Returns ResultAsync<T, E>

Methods

  • Returns AsyncGenerator<Err<never, E>, T>

  • Parameters

    • f: (t: T) => unknown

    Returns ResultAsync<T, E>

  • Type Parameters

    • R extends Result<unknown, unknown>

    Parameters

    • f: (t: T) => R

    Returns ResultAsync<InferOkTypes<R>, E | InferErrTypes<R>>

  • Type Parameters

    Parameters

    • f: (t: T) => R

    Returns ResultAsync<InferAsyncOkTypes<R>, E | InferAsyncErrTypes<R>>

  • Type Parameters

    • U
    • F

    Parameters

    Returns ResultAsync<U, E | F>

  • Type Parameters

    • F

    Parameters

    Returns ResultAsync<T, E | F>

  • Type Parameters

    • A

    Parameters

    • f: (t: T) => A | Promise<A>

    Returns ResultAsync<A, E>

  • Type Parameters

    • U

    Parameters

    • f: (e: E) => U | Promise<U>

    Returns ResultAsync<T, U>

  • Type Parameters

    • A
    • B = A

    Parameters

    • ok: (t: T) => A
    • _err: (e: E) => B

    Returns Promise<A | B>

  • Type Parameters

    • R extends Result<unknown, unknown>

    Parameters

    • f: (e: E) => R

    Returns ResultAsync<T | InferOkTypes<R>, InferErrTypes<R>>

  • Type Parameters

    Parameters

    • f: (e: E) => R

    Returns ResultAsync<T | InferAsyncOkTypes<R>, InferAsyncErrTypes<R>>

  • Type Parameters

    • U
    • A

    Parameters

    Returns ResultAsync<T | U, A>

  • Parameters

    • f: (t: E) => unknown

    Returns ResultAsync<T, E>

  • Returns AsyncGenerator<Err<never, E>, T>

    will be removed in 9.0.0.

    You can use safeTry without this method.

    safeTry(async function* () {
    const okValue = yield* yourResult
    })

    Emulates Rust's ? operator in safeTry's body. See also safeTry.

  • Attaches callbacks for the resolution and/or rejection of the Promise.

    Type Parameters

    • A
    • B

    Parameters

    • OptionalsuccessCallback: (res: Result<T, E>) => A | PromiseLike<A>
    • OptionalfailureCallback: (reason: unknown) => B | PromiseLike<B>

    Returns PromiseLike<A | B>

    A Promise for the completion of which ever callback is executed.

  • Type Parameters

    • A

    Parameters

    Returns Promise<T | A>

  • Type Parameters

    Parameters

    • asyncResultList: T

    Returns CombineResultAsyncs<T>

  • Type Parameters

    Parameters

    • asyncResultList: T

    Returns CombineResultAsyncs<T>

  • Type Parameters

    Parameters

    • asyncResultList: T

    Returns CombineResultsWithAllErrorsArrayAsync<T>

  • Type Parameters

    Parameters

    • asyncResultList: T

    Returns CombineResultsWithAllErrorsArrayAsync<T>

  • Type Parameters

    • T
    • E

    Parameters

    • promise: PromiseLike<T>
    • errorFn: (e: unknown) => E

    Returns ResultAsync<T, E>

  • Type Parameters

    • T
    • E = never

    Parameters

    • promise: PromiseLike<T>

    Returns ResultAsync<T, E>

  • Type Parameters

    • A extends readonly any[]
    • R
    • E

    Parameters

    • fn: (...args: A) => Promise<R>
    • OptionalerrorFn: (err: unknown) => E

    Returns (...args: A) => ResultAsync<R, E>