API reference › @evolu/common › Result
Type-safe error handling with Result types.
Composition
| Function | Description |
|---|---|
| allResult | Extracts all values from an array of Results. |
| anyResult | Returns the first successful Result. |
| mapResult | Maps items to Results and extracts all values. |
Utilities
| Type Alias | Description |
|---|---|
| AnyResult | Shorthand for a Result with any type parameters. |
| ExcludeDone | Removes Done from an error union. |
| InferDone | Extracts the done value type from a NextResult. |
| InferErr | Extracts the error type from a Result. |
| InferOk | Extracts the value type from a Result. |
| OnlyDone | Extracts only Done from an error union. |
Functions
| Function | Description |
|---|---|
| done | Constructs a Done value. |
| err | Creates an Err result. |
| getOk | Extracts the value from a Result whose error type is never. |
| getOrNull | Extracts the value from a Result if it is an Ok, or returns null if it is an Err. |
| getOrThrow | Returns the value from an Ok Result, or throws if it is an Err. |
| isErr | Type guard for Err results. |
| isOk | Type guard for Ok results. |
| ok | Creates an Ok result. |
| tryAsync | Wraps an async function that may throw, returning a Result. |
| trySync | Wraps a synchronous function that may throw, returning a Result. |
Interfaces
| Interface | Description |
|---|---|
| Done | A signal indicating normal completion of a pull-based protocol. |
| Err | An error Result. |
| Ok | A successful Result. |
Type Aliases
| Type Alias | Description |
|---|---|
| NextResult | A result for a pull-based protocol with three outcomes. |
| Result | The 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. |