API reference / @evolu/common / Result / getOrThrow
Function: getOrThrow()
function getOrThrow<T, E>(result): T;
Defined in: packages/common/src/Result.ts:332
Extracts the value from a Result if it is an Ok, or throws an error
if it is an Err.
Intended usage:
- For critical code paths (e.g., app startup, config values) where failure should crash the app.
- Not recommended for general error handling in application logic—prefer explicit checks.
Example
// At app startup, crash if config is invalid:
const config = getOrThrow(loadConfig());
// Safe to use config here
Throws: Error with the original error attached as cause.
Type Parameters
| Type Parameter |
|---|
T |
E |
Parameters
| Parameter | Type |
|---|---|
result | Result<T, E> |
Returns
T