Skip to main content

Function: unwrap()

unwrap<T, E>(result): T

Defined in: src/types/result.ts:191

Unwraps a Result, returning the value or throwing the error.

Type Parameters​

• T

Success value type

• E extends Error

Error type

Parameters​

result​

Result<T, E>

Result to unwrap

Returns​

T

The success value

Throws​

The error if Result is Err

Remarks​

Use this function when you're confident the Result will be Ok, or when you want to propagate errors via exceptions.

Prefer pattern matching with isOk/isErr for safer error handling.

Example​

const result = Ok(42);
const value = unwrap(result); // 42

const errorResult = Err(new Error('Failed'));
const value2 = unwrap(errorResult); // Throws Error('Failed')