Readonly<{ readonly ok: false; }> Frozen object representing a failed result.
6 declarations
Readonly<{ readonly ok: false; }> Frozen object representing a failed result.
Readonly<{ readonly ok: true; }> Frozen object representing a successful result.
Result<TValue, TError> An alternative pattern to throwing and catching errors. Uses the type system to strongly type error return values when desired. Catching errors is then reserved for unexpected situations.
TValueobjectTErrorobjectA custom error class that's thrown by unwrap. Wraps a failed Result with an optional message, and also accepts an optional message that overrides the result's. Useful for generic handling of unwrapped results to forward custom messages and other failed result data.
ErrorDEFAULT_MESSAGEresulttype {ok: false; message?: string}
constructortype new (result: { ok: false; message?: string | undefined; }, message?: string | undefined, options?: ErrorOptions | undefined): ResultError
result{ ok: false; message?: string | undefined; }message?string | undefinedoptions?ErrorOptions | undefined<TValue extends { value?: unknown; }, TError extends { message?: string; }>(result: Result<TValue, TError>, message?: string | undefined): TValue["value"] A helper that says,
"hey I know this is wrapped in a Result, but I expect it to be ok,
so if it's not, I understand it will throw an error that wraps the result".
resultSome Result object.
Result<TValue, TError>message?Optional custom error message.
string | undefinedTValue["value"] The wrapped value.
<TError extends object>(result: Result<object, TError>, message?: string): { ok: false; } & TError A helper that does the opposite of unwrap, throwing if the Result is ok.
Note that while unwrap returns the wrapped value, unwrap_error returns the entire result.
resultSome Result object.
Result<object, TError>messageOptional custom error message.
string'Failed to unwrap result error'{ ok: false; } & TError The type-narrowed result.