aboutsummaryrefslogtreecommitdiff
path: root/utils/result/types.ts
blob: ee95c0839a13d99be53a49d94723cdc56c6bbaa6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/** A successful result carrying a value. */
export type Ok<T> = { readonly ok: true; readonly value: T }

/** A failed result carrying an error. */
export type Err<E> = { readonly ok: false; readonly error: E }

/**
 * Result<T, E> — a recoverable-error return type for functions that can
 * fail without throwing. Used at system boundaries (save/load, content
 * validation, manifest fetch) where the caller needs to decide whether a
 * failure is fatal. Internal pure logic uses plain returns and throws
 * Error for programmer errors (rules/01-code-style.md).
 */
export type Result<T, E = Error> = Ok<T> | Err<E>