Skip to content

unwrap

ts
function Result.unwrap(result: Result<T, E>): T

Unwraps the Ok value from the result. If the result is an Err, throws a ResultError with a default message.

Example

ts
Result.unwrap(ok(5));
// 5

Result.unwrap(err("fail"));
// throws ResultError("Called Err.unwrap()")
ts
pipe(ok(5), Result.unwrap());
// 5