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