API reference@evolu/common › Result

Type-safe error handling with Result types.

Composition

FunctionDescription
allResultExtracts all values from an array of Results.
anyResultReturns the first successful Result.
mapResultMaps items to Results and extracts all values.

Utilities

Type AliasDescription
AnyResultShorthand for a Result with any type parameters.
ExcludeDoneRemoves Done from an error union.
InferDoneExtracts the done value type from a NextResult.
InferErrExtracts the error type from a Result.
InferOkExtracts the value type from a Result.
OnlyDoneExtracts only Done from an error union.

Functions

FunctionDescription
doneConstructs a Done value.
errCreates an Err result.
getOkExtracts the value from a Result whose error type is never.
getOrNullExtracts the value from a Result if it is an Ok, or returns null if it is an Err.
getOrThrowReturns the value from an Ok Result, or throws if it is an Err.
isErrType guard for Err results.
isOkType guard for Ok results.
okCreates an Ok result.
tryAsyncWraps an async function that may throw, returning a Result.
trySyncWraps a synchronous function that may throw, returning a Result.

Interfaces

InterfaceDescription
DoneA signal indicating normal completion of a pull-based protocol.
ErrAn error Result.
OkA successful Result.

Type Aliases

Type AliasDescription
NextResultA result for a pull-based protocol with three outcomes.
ResultThe problem with throw in JavaScript is that the caught value is always of unknown type. We can't be sure all errors have been handled because the TypeScript compiler can't tell us what was thrown — we can't use exhaustiveCheck.