Readonly<{ readonly ok: false; }> import {NOT_OK} from '@fuzdev/fuz_util/result.js'; Frozen object representing a failed result.
6 declarations
Readonly<{ readonly ok: false; }> import {NOT_OK} from '@fuzdev/fuz_util/result.js'; Frozen object representing a failed result.
Readonly<{ readonly ok: true; }> import {OK} from '@fuzdev/fuz_util/result.js'; Frozen object representing a successful result.
Result<TValue, TError> import type {Result} from '@fuzdev/fuz_util/result.js'; 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.
Result<TValue = object, TError = object>TValueobjectTErrorobjectimport {ResultError} from '@fuzdev/fuz_util/result.js'; A 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_MESSAGEtype string
resulttype { 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"] import {unwrap} from '@fuzdev/fuz_util/result.js'; 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".
resultResult<TValue, TError>message?string | undefinedTValue["value"] unwrap<TValue extends { value?: unknown }, TError extends { message?: string }>TValue{ value?: unknown }TError{ message?: string }ResultError - if `result.ok` is false<TError extends object>(result: Result<object, TError>, message?: string): { ok: false; } & TError import {unwrap_error} from '@fuzdev/fuz_util/result.js'; 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.
resultResult<object, TError>messagestring'Failed to unwrap result error'{ ok: false; } & TError unwrap_error<TError extends object>TErrorobjectError - if `result.ok` is true