Skip to content

@kaelyx/ts-kit / result / unwrap

Function: unwrap() ​

unwrap<T, E>(result): T

Defined in: result/unwrap/unwrap.ts:21

Returns the value of a successful Result, or throws if the Result failed. Use unwrapOr if you want a fallback value instead of an exception.

Type Parameters ​

T ​

T

E ​

E

Parameters ​

result ​

Result<T, E>

The Result to unwrap.

Returns ​

T

The value of the Result when ok is true.

Throws ​

An Error when ok is false. The original error is attached as the cause.

Example ​

ts
unwrap(ok(42)) // 42
unwrap(err('Something went wrong')) // throws Error('Attempted to unwrap an Err result')