Outcome
Outcome:
object
Defined in: src/core.ts:21
Type Declaration
Section titled “Type Declaration”from:
object=asOutcome
Converts a foreign Result via a registered adapter (or returns ours as is); undefined if it isn’t one.
fromError
Section titled “fromError”fromError: <
T,E>(error) =>Outcome<T,E> =fail
Type Parameters
Section titled “Type Parameters”T = never
E = unknown
Parameters
Section titled “Parameters”E
Returns
Section titled “Returns”Outcome<T, E>
fromResult
Section titled “fromResult”fromResult: <
T>(result) =>Outcome<T,never> =ok
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”result
Section titled “result”T
Returns
Section titled “Returns”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)?
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”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.
Call Signature
Section titled “Call Signature”<
R>(fn):TryResult<R,unknown>
Type Parameters
Section titled “Type Parameters”R
Parameters
Section titled “Parameters”() => R
Returns
Section titled “Returns”TryResult<R, unknown>
Call Signature
Section titled “Call Signature”<
R,E>(options):TryResult<R,E>
Type Parameters
Section titled “Type Parameters”R
E
Parameters
Section titled “Parameters”options
Section titled “options”(error) => E
() => R
Returns
Section titled “Returns”TryResult<R, E>
unwrap
Section titled “unwrap”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.
Type Parameters
Section titled “Type Parameters”O extends readonly Outcome<any, any>[]
Parameters
Section titled “Parameters”outcomes
Section titled “outcomes”O
Returns
Section titled “Returns”Outcome<{ -readonly [K in string | number | symbol]: OutcomeValue<O[K]> }, OutcomeError<O[number]>>
match()
Section titled “match()”match<
T,E,H>(outcome,handlers):ReturnType<H[keyofH] & ((…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.
Type Parameters
Section titled “Type Parameters”T
E
H extends OutcomeHandlers<T, E, unknown>
Parameters
Section titled “Parameters”outcome
Section titled “outcome”Outcome<T, E>
handlers
Section titled “handlers”H
Returns
Section titled “Returns”ReturnType<H[keyof H] & ((…args) => any)>
partition()
Section titled “partition()”partition<
O>(outcomes):object
Splits outcomes into their values and their errors, keeping order within each.
Type Parameters
Section titled “Type Parameters”O extends Outcome<any, any>
Parameters
Section titled “Parameters”outcomes
Section titled “outcomes”readonly O[]
Returns
Section titled “Returns”object
errors
Section titled “errors”errors:
OutcomeError<O>[]
values
Section titled “values”values:
OutcomeValue<O>[]
unwrapErr()
Section titled “unwrapErr()”unwrapErr<
E,C>(outcome,code?):ErrorWithCode<E,C>
The error (optionally checking its code), or throws if the outcome succeeded / has another code.
Type Parameters
Section titled “Type Parameters”E
C extends never = ErrorCodes<E>
Parameters
Section titled “Parameters”outcome
Section titled “outcome”Outcome<unknown, E>
C
Returns
Section titled “Returns”ErrorWithCode<E, C>