The error value if Result.Err
, otherwise defaultValue
.
const okResult = Result.ok('success');
const errResult = Result.err('failure');
assert(Result.unwrapErrOr(okResult, 'default') === 'default');
assert(Result.unwrapErrOr(errResult, 'default') === 'failure');
const unwrapError = Result.unwrapErrOr('fallback error');
assert(unwrapError(Result.err('boom')) === 'boom');
assert(unwrapError(Result.ok('no error')) === 'fallback error');
Unwraps a Result
, returning the error value or a default value if it is
Result.Ok
.
The type of the default value.
The value to return if result
is Result.Ok
.
The error value if Result.Err
, otherwise defaultValue
.
const okResult = Result.ok('success');
const errResult = Result.err('failure');
assert(Result.unwrapErrOr(okResult, 'default') === 'default');
assert(Result.unwrapErrOr(errResult, 'default') === 'failure');
const unwrapError = Result.unwrapErrOr('fallback error');
assert(unwrapError(Result.err('boom')) === 'boom');
assert(unwrapError(Result.ok('no error')) === 'fallback error');
Unwraps a
Result
, returning the error value or a default value if it isResult.Ok
.