API Reference / @evolu/common / Result / getOrThrow

Function: getOrThrow()

function getOrThrow<T, E>(result): T;

Defined in: packages/common/src/Result.ts:357

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

Type Parameters

Type Parameter
T
E

Parameters

ParameterType
resultResult<T, E>

Returns

T

Was this page helpful?