Skip to content
Buy me a coffee

Outcome

Outcome: object

Defined in: src/core.ts:21

from: object = asOutcome

Converts a foreign Result via a registered adapter (or returns ours as is); undefined if it isn’t one.

fromError: <T, E>(error) => Outcome<T, E> = fail

T = never

E = unknown

E

Outcome<T, E>

fromResult: <T>(result) => Outcome<T, never> = ok

T

T

Outcome<T, never>

is: (value) => value is Outcome<unknown, unknown> = isOutcome

Was this value created with Outcome.fromResult / Outcome.fromError (from any copy of the package)?

unknown

value is Outcome<unknown, unknown>

try: {<R>(fn): TryResult<R, unknown>; <R, E>(options): TryResult<R, E>; } = tryOutcome

Runs fn and captures a throw/rejection as a failed outcome; catch maps the error (typed). Stays synchronous for a synchronous fn.

<R>(fn): TryResult<R, unknown>

R

() => R

TryResult<R, unknown>

<R, E>(options): TryResult<R, E>

R

E

(error) => E

() => R

TryResult<R, E>

unwrap: object = unwrapOutcome

The value, or throws the error.

all<O>(outcomes): Outcome<{ -readonly [K in string | number | symbol]: OutcomeValue<O[K]> }, OutcomeError<O[number]>>

ok(values) if every outcome succeeded, otherwise the first failure.

O extends readonly Outcome<any, any>[]

O

Outcome<{ -readonly [K in string | number | symbol]: OutcomeValue<O[K]> }, OutcomeError<O[number]>>

match<T, E, H>(outcome, handlers): ReturnType<H[keyof H] & ((…args) => any)>

Exhaustive handling by error code: Outcome.match(await pipeline.settle(cb), { ok: (v) => …, TIMEOUT: (e) => …, CIRCUIT_OPEN: (e) => …, UNEXPECTED: (e) => … }). Add a breaker and forget its handler: compile error.

T

E

H extends OutcomeHandlers<T, E, unknown>

Outcome<T, E>

H

ReturnType<H[keyof H] & ((…args) => any)>

partition<O>(outcomes): object

Splits outcomes into their values and their errors, keeping order within each.

O extends Outcome<any, any>

readonly O[]

object

errors: OutcomeError<O>[]

values: OutcomeValue<O>[]

unwrapErr<E, C>(outcome, code?): ErrorWithCode<E, C>

The error (optionally checking its code), or throws if the outcome succeeded / has another code.

E

C extends never = ErrorCodes<E>

Outcome<unknown, E>

C

ErrorWithCode<E, C>