Skip to content

unwrapOr

ts
function Result.unwrapOr(result: Result<T, E>, or: U): T | U

Unwraps the Ok value from the result, or returns the or value if the result is an Err.

Example

ts
Result.unwrapOr(ok(5), 0);
// 5

Result.unwrapOr(err("fail"), 0);
// 0
ts
pipe(err("fail"), Result.unwrapOr(0));
// 0