Ok<T, E>
Package: antithrow
A Result that succeeded. Carries the successful value on .value.
Signature
class Ok<out T, out E = never> extends ResultBase<T, E> {
constructor(value: T);
readonly value: T;
}
| Parameter | Description |
|---|---|
T | The success value type. |
E | The error type (defaults to never). |
Constructor
new Ok<T, E>(value: T): Ok<T, E>;
| Argument | Type | Description |
|---|---|---|
value | T | The success value. |
Properties
| Name | Type | Description |
|---|---|---|
value | T | Readonly success value. |
Instance methods
isOk(): true— alwaystrue; narrowsthistoOk<T, E>.isErr(): false— alwaysfalse.isPending(): false— alwaysfalse.unwrap(): T— returnsvalue.unwrapErr(): never— throwsUnwrapError.unwrapOr(_: T): T— returnsvalue.unwrapOrElse(_: (error: E) => T): T— returnsvalue.settle(): PromiseLike<Ok<T, E>>— resolves tothis.
All chainable methods (map, mapErr, andThen, and, or, orElse, flatten, mapOr, mapOrElse) behave as expected for Ok: transforms on the value branch run, transforms on the error branch are no-ops. See methods.
Ok also implements [Symbol.iterator] so Result.do can yield* it and continue with the value.
Throws
unwrapErr() throws UnwrapError. No other method throws.
Example
import { Ok } from "antithrow";
const success = new Ok<number, "missing">(42);
success.value; // 42
success.isOk(); // true
success.unwrap(); // 42
See also
Err— the failure shape.Pending— the in-flight shape.- Chainable methods.