The Result.Base
type to unwrap.
The Result
to unwrap.
The success value if Result.Ok
, otherwise undefined
.
const okResult = Result.ok(42);
const errResult = Result.err('oops');
// Result.unwrapOk returns the value for Ok results
assert(Result.unwrapOk(okResult) === 42);
// Result.unwrapOk returns undefined for Err results
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
assert(Result.unwrapOk(errResult) === undefined);
Unwraps a Result
, returning the success value or undefined
if it's an
error.
This function provides a safe way to extract success values from Results without throwing exceptions. It has overloaded behavior based on the type:
Result.Ok<T>
: Always returns T
(guaranteed by type system)Result<T, E>
: Returns T | undefined
The Result
to unwrap.
The success value if Result.Ok
, otherwise undefined
.
const okResult = Result.ok(42);
const errResult = Result.err('oops');
// Result.unwrapOk returns the value for Ok results
assert(Result.unwrapOk(okResult) === 42);
// Result.unwrapOk returns undefined for Err results
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
assert(Result.unwrapOk(errResult) === undefined);
Unwraps a
Result
, returning the success value orundefined
if it's an error.This function provides a safe way to extract success values from Results without throwing exceptions. It has overloaded behavior based on the type:
Result.Ok<T>
: Always returnsT
(guaranteed by type system)Result<T, E>
: ReturnsT | undefined