resultar 3.5.1 → 3.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -7,21 +7,21 @@ interface ErrorConfig {
7
7
  type PipeFn<Input, Output> = (input: Input) => Output;
8
8
  declare abstract class Pipeable {
9
9
  /**
10
- * Passes this value through one or more transformation functions.
11
- *
12
- * Use `pipe` to package reusable Result or ResultAsync combinators without hiding the underlying
13
- * type.
14
- */
10
+ * Passes this value through one or more transformation functions.
11
+ *
12
+ * Use `pipe` to package reusable Result or ResultAsync combinators without hiding the underlying
13
+ * type.
14
+ */
15
15
  pipe<A>(ab: PipeFn<this, A>): A;
16
16
  pipe<A, B>(ab: PipeFn<this, A>, bc: PipeFn<A, B>): B;
17
17
  pipe<A, B, C>(ab: PipeFn<this, A>, bc: PipeFn<A, B>, cd: PipeFn<B, C>): C;
18
18
  }
19
19
  //#endregion
20
20
  //#region src/utils.d.ts
21
- type ExtractOkTypes<T extends readonly Result<unknown, unknown>[]> = { [idx in keyof T]: T[idx] extends Result<infer U, unknown> ? U : never };
22
- type ExtractOkAsyncTypes<T extends readonly ResultAsync<unknown, unknown>[]> = { [idx in keyof T]: T[idx] extends ResultAsync<infer U, unknown> ? U : never };
23
- type ExtractErrTypes<T extends readonly Result<unknown, unknown>[]> = { [idx in keyof T]: T[idx] extends Result<unknown, infer E> ? E : never };
24
- type ExtractErrAsyncTypes<T extends readonly ResultAsync<unknown, unknown>[]> = { [idx in keyof T]: T[idx] extends ResultAsync<unknown, infer E> ? E : never };
21
+ type ExtractOkTypes<T extends readonly Result<unknown, unknown>[]> = { [idx in keyof T]: T[idx] extends Result<infer U, unknown> ? U : never; };
22
+ type ExtractOkAsyncTypes<T extends readonly ResultAsync<unknown, unknown>[]> = { [idx in keyof T]: T[idx] extends ResultAsync<infer U, unknown> ? U : never; };
23
+ type ExtractErrTypes<T extends readonly Result<unknown, unknown>[]> = { [idx in keyof T]: T[idx] extends Result<unknown, infer E> ? E : never; };
24
+ type ExtractErrAsyncTypes<T extends readonly ResultAsync<unknown, unknown>[]> = { [idx in keyof T]: T[idx] extends ResultAsync<unknown, infer E> ? E : never; };
25
25
  type InferOkTypes<R> = R extends Result<infer T, unknown> ? T : never;
26
26
  type InferErrTypes<R> = R extends Result<unknown, infer E> ? E : never;
27
27
  type InferAsyncOkTypes<R> = R extends ResultAsync<infer T, unknown> ? T : never;
@@ -61,21 +61,21 @@ type ExcludeReasonTag<E, ErrorTag extends string, ReasonTag extends string> = Ex
61
61
  }> | ErrorWithRemainingReason<ErrorForTag$1<E, ErrorTag>, Exclude<ReasonsOf<E, ErrorTag>, {
62
62
  readonly _tag: ReasonTag;
63
63
  }>>;
64
- type CatchTagHandlerResult<Handlers> = { readonly [Key in keyof Handlers]: Handlers[Key] extends ((...args: infer _Args) => infer R) ? R : never }[keyof Handlers];
65
- type CatchReasonHandlerResult<Handlers> = { readonly [Key in keyof Handlers]: Handlers[Key] extends ((...args: infer _Args) => infer R) ? R : never }[keyof Handlers];
66
- type MatchTagHandlerResult<Handlers> = { readonly [Key in keyof Handlers]: Handlers[Key] extends ((...args: infer _Args) => infer R) ? R : never }[keyof Handlers];
67
- type CatchTagHandlers<E, Handlers, R> = { readonly [Tag in keyof Handlers]: Tag extends TagsOf<E> ? (error: ErrorForTag$1<E, Tag & string>) => R : never };
64
+ type CatchTagHandlerResult<Handlers> = { readonly [Key in keyof Handlers]: Handlers[Key] extends ((...args: infer _Args) => infer R) ? R : never; }[keyof Handlers];
65
+ type CatchReasonHandlerResult<Handlers> = { readonly [Key in keyof Handlers]: Handlers[Key] extends ((...args: infer _Args) => infer R) ? R : never; }[keyof Handlers];
66
+ type MatchTagHandlerResult<Handlers> = { readonly [Key in keyof Handlers]: Handlers[Key] extends ((...args: infer _Args) => infer R) ? R : never; }[keyof Handlers];
67
+ type CatchTagHandlers<E, Handlers, R> = { readonly [Tag in keyof Handlers]: Tag extends TagsOf<E> ? (error: ErrorForTag$1<E, Tag & string>) => R : never; };
68
68
  type ResultCatchTagHandlers<E, Handlers> = CatchTagHandlers<E, Handlers, Result<unknown, unknown>>;
69
69
  type ResultAsyncCatchTagHandlers<E, Handlers> = CatchTagHandlers<E, Handlers, Result<unknown, unknown> | ResultAsync<unknown, unknown>>;
70
- type CatchReasonHandlers<E, ErrorTag extends string, Handlers, R> = { readonly [ReasonTag in keyof Handlers]: ReasonTag extends ReasonTagsOf<E, ErrorTag> ? (reason: ReasonForTag<E, ErrorTag, ReasonTag & string>, error: ErrorForTag$1<E, ErrorTag>) => R : never };
70
+ type CatchReasonHandlers<E, ErrorTag extends string, Handlers, R> = { readonly [ReasonTag in keyof Handlers]: ReasonTag extends ReasonTagsOf<E, ErrorTag> ? (reason: ReasonForTag<E, ErrorTag, ReasonTag & string>, error: ErrorForTag$1<E, ErrorTag>) => R : never; };
71
71
  type ResultCatchReasonHandlers<E, ErrorTag extends string, Handlers> = CatchReasonHandlers<E, ErrorTag, Handlers, Result<unknown, unknown>>;
72
72
  type ResultAsyncCatchReasonHandlers<E, ErrorTag extends string, Handlers> = CatchReasonHandlers<E, ErrorTag, Handlers, Result<unknown, unknown> | ResultAsync<unknown, unknown>>;
73
- type MatchTagHandlers<E, Handlers> = { readonly [Tag in ErrorTagsOf<E>]: (error: ErrorForTag$1<E, Tag>) => unknown } & ([UntaggedError$1<E>] extends [never] ? {
73
+ type MatchTagHandlers<E, Handlers> = { readonly [Tag in ErrorTagsOf<E>]: (error: ErrorForTag$1<E, Tag>) => unknown; } & ([UntaggedError$1<E>] extends [never] ? {
74
74
  readonly Error?: (error: Error) => unknown;
75
75
  } : {
76
76
  readonly Error: (error: UntaggedError$1<E>) => unknown;
77
- }) & { readonly [Tag in keyof Handlers]: Tag extends ErrorTagsOf<E> | "Error" ? Handlers[Tag] : never };
78
- type PartialMatchTagHandlers<E, Handlers> = { readonly [Tag in keyof Handlers]: Tag extends ErrorTagsOf<E> ? (error: ErrorForTag$1<E, Tag & string>) => unknown : Tag extends "Error" ? (error: Extract<E, Error>) => unknown : never };
77
+ }) & { readonly [Tag in keyof Handlers]: Tag extends ErrorTagsOf<E> | "Error" ? Handlers[Tag] : never; };
78
+ type PartialMatchTagHandlers<E, Handlers> = { readonly [Tag in keyof Handlers]: Tag extends ErrorTagsOf<E> ? (error: ErrorForTag$1<E, Tag & string>) => unknown : Tag extends "Error" ? (error: Extract<E, Error>) => unknown : never; };
79
79
  //#endregion
80
80
  //#region src/result.d.ts
81
81
  type ResultFinalizer<T, E> = (value: T | undefined, error: E | undefined) => void;
@@ -83,8 +83,8 @@ type MatchOkHandler<T, A> = (value: T) => A;
83
83
  type MatchErrorHandler<E, B> = (error: E) => B;
84
84
  type ResultCandidate = () => Result<unknown, unknown>;
85
85
  type ResultRecord = Readonly<Record<string, Result<unknown, unknown>>>;
86
- type CombineResultsRecord<T extends ResultRecord> = Result<{ readonly [Key in keyof T]: InferOkTypes<T[Key]> }, InferErrTypes<T[keyof T]>>;
87
- type CombineResultsRecordWithAllErrors<T extends ResultRecord> = Result<{ readonly [Key in keyof T]: InferOkTypes<T[Key]> }, InferErrTypes<T[keyof T]>[]>;
86
+ type CombineResultsRecord<T extends ResultRecord> = Result<{ readonly [Key in keyof T]: InferOkTypes<T[Key]>; }, InferErrTypes<T[keyof T]>>;
87
+ type CombineResultsRecordWithAllErrors<T extends ResultRecord> = Result<{ readonly [Key in keyof T]: InferOkTypes<T[Key]>; }, InferErrTypes<T[keyof T]>[]>;
88
88
  type CombineResultsIterable<R extends Result<unknown, unknown>> = Result<readonly InferOkTypes<R>[], InferErrTypes<R>>;
89
89
  type CombineResultsIterableWithAllErrors<R extends Result<unknown, unknown>> = Result<readonly InferOkTypes<R>[], InferErrTypes<R>[]>;
90
90
  type ResultLoopCollected<R extends Result<unknown, unknown>> = Result<readonly InferOkTypes<R>[], InferErrTypes<R>>;
@@ -148,298 +148,305 @@ interface ResultIfOptions<OnTrue extends Result<unknown, unknown>, OnFalse exten
148
148
  readonly onTrue: () => OnTrue;
149
149
  }
150
150
  /**
151
- * A Result interface that is used to define the methods that are available on a
152
- * `Result` object.
153
- *
154
- * The immutability of the `Result` object is maintained by the interface.
155
- */
151
+ * A Result interface that is used to define the methods that are available on a
152
+ * `Result` object.
153
+ *
154
+ * The immutability of the `Result` object is maintained by the interface.
155
+ */
156
156
  interface Resultable<T, E> {
157
157
  get value(): T;
158
158
  get error(): E;
159
159
  /**
160
- * Used to check if a `Result` is an `OK`
161
- *
162
- * @returns `true` if the result is an `OK` variant of Result
163
- */
160
+ * Used to check if a `Result` is an `OK`
161
+ *
162
+ * @returns `true` if the result is an `OK` variant of Result
163
+ */
164
164
  isOk: () => boolean;
165
165
  /**
166
- * Used to check if a `Result` is an `Err`
167
- *
168
- * @returns `true` if the result is an `Err` variant of Result
169
- */
166
+ * Used to check if a `Result` is an `Err`
167
+ *
168
+ * @returns `true` if the result is an `Err` variant of Result
169
+ */
170
170
  isErr: () => boolean;
171
171
  /**
172
- * Unwrap the `Ok` value, or return the default if there is an `Err`
173
- *
174
- * @param v the default value to return if there is an `Err`
175
- */
172
+ * Unwrap the `Ok` value, or return the default if there is an `Err`
173
+ *
174
+ * @param v the default value to return if there is an `Err`
175
+ */
176
176
  unwrapOr: <A>(defaultValue: A) => T | A;
177
177
  /**
178
- * **This method is unsafe, and should only be used in a test environments**
179
- *
180
- * Takes a `Result<T, E>` and returns a `T` when the result is an `Ok`, otherwise it throws a custom object.
181
- *
182
- * @param config
183
- */
178
+ * **This method is unsafe, and should only be used in a test environments**
179
+ *
180
+ * Takes a `Result<T, E>` and returns a `T` when the result is an `Ok`, otherwise it throws a custom object.
181
+ *
182
+ * @param config
183
+ */
184
184
  _unsafeUnwrap: (config?: ErrorConfig) => T;
185
185
  /**
186
- * **This method is unsafe, and should only be used in a test environments**
187
- *
188
- * takes a `Result<T, E>` and returns a `E` when the result is an `Err`,
189
- * otherwise it throws a custom object.
190
- *
191
- * @param config
192
- */
186
+ * **This method is unsafe, and should only be used in a test environments**
187
+ *
188
+ * takes a `Result<T, E>` and returns a `E` when the result is an `Err`,
189
+ * otherwise it throws a custom object.
190
+ *
191
+ * @param config
192
+ */
193
193
  _unsafeUnwrapErr: (config?: ErrorConfig) => E;
194
194
  }
195
+ /** Operations shared by the Ok and Err variants of `Result<T, E>`. */
195
196
  interface ResultOperations<T, E> {
196
197
  /**
197
- * Narrows this result to the Ok variant.
198
- */
198
+ * Narrows this result to the Ok variant.
199
+ */
199
200
  isOk: () => this is OkResult<T, E>;
200
201
  /**
201
- * Narrows this result to the Err variant.
202
- */
202
+ * Narrows this result to the Err variant.
203
+ */
203
204
  isErr: () => this is ErrResult<T, E>;
204
205
  /**
205
- * Returns the Ok value, or `defaultValue` when this result is Err.
206
- */
206
+ * Returns the Ok value, or `defaultValue` when this result is Err.
207
+ */
207
208
  unwrapOr: <A>(defaultValue: A) => T | A;
208
209
  /**
209
- * Returns the Ok value or throws a Resultar diagnostic error when this result is Err.
210
- *
211
- * Prefer `match`, `unwrapOr`, or explicit error handling in application code. This helper is
212
- * intended for tests and trusted final boundaries.
213
- */
210
+ * Returns the Ok value or throws a Resultar diagnostic error when this result is Err.
211
+ *
212
+ * Prefer `match`, `unwrapOr`, or explicit error handling in application code. This helper is
213
+ * intended for tests and trusted final boundaries.
214
+ */
214
215
  _unsafeUnwrap: (config?: ErrorConfig) => T;
215
216
  /**
216
- * Returns the Err value or throws a Resultar diagnostic error when this result is Ok.
217
- *
218
- * Prefer `match`, `isErr`, or explicit error handling in application code. This helper is intended
219
- * for tests.
220
- */
217
+ * Returns the Err value or throws a Resultar diagnostic error when this result is Ok.
218
+ *
219
+ * Prefer `match`, `isErr`, or explicit error handling in application code. This helper is intended
220
+ * for tests.
221
+ */
221
222
  _unsafeUnwrapErr: (config?: ErrorConfig) => E;
222
223
  /**
223
- * Maps the Ok value while preserving the error channel.
224
- */
224
+ * Maps the Ok value while preserving the error channel.
225
+ */
225
226
  map: <X>(f: (t: T) => X) => Result<X, E>;
226
227
  /**
227
- * Replaces the Ok value with a constant while preserving the error channel.
228
- */
228
+ * Replaces the Ok value with a constant while preserving the error channel.
229
+ */
229
230
  as: <X>(value: X) => Result<X, E>;
230
231
  /**
231
- * Keeps the Ok value only when the predicate passes; otherwise returns an Err from `onFalse`.
232
- */
232
+ * Keeps the Ok value only when the predicate passes; otherwise returns an Err from `onFalse`.
233
+ */
233
234
  filterOrElse: {
234
235
  <U extends T, F>(predicate: (value: T) => value is U, onFalse: (value: T) => F): Result<U, E | F>;
235
236
  <F>(predicate: (value: T) => boolean, onFalse: (value: T) => F): Result<T, E | F>;
236
237
  };
237
238
  /**
238
- * Maps the Err value while preserving the Ok value.
239
- */
239
+ * Maps the Err value while preserving the Ok value.
240
+ */
240
241
  mapErr: <X>(fn: (t: E) => X) => Result<T, X>;
241
242
  /**
242
- * Chains another fallible operation from the Ok value.
243
- *
244
- * Use this instead of `map` when the callback returns another `Result`.
245
- */
243
+ * Chains another fallible operation from the Ok value.
244
+ *
245
+ * Use this instead of `map` when the callback returns another `Result`.
246
+ */
246
247
  andThen: <X, Y>(f: (t: T) => Result<X, Y>) => Result<X, E | Y>;
247
248
  /**
248
- * Branches from the Ok value into one of two fallible Result branches.
249
- */
249
+ * Branches from the Ok value into one of two fallible Result branches.
250
+ */
250
251
  if: (fCondition: (t: T) => boolean) => {
251
252
  true: <X1, Y1>(fTrue: (t: T) => Result<X1, Y1>) => {
252
253
  false: <X2, Y2>(fFalse: (t: T) => Result<X2, Y2>) => Result<X1 | X2, Y1 | Y2 | E>;
253
254
  };
254
255
  };
255
256
  /**
256
- * Recovers from Err with another Result.
257
- */
257
+ * Recovers from Err with another Result.
258
+ */
258
259
  orElse: <R extends Result<unknown, unknown>>(f: (e: E) => R) => Result<InferOkTypes<R> | T, InferErrTypes<R>>;
259
260
  /**
260
- * Recovers from a specific tagged error by `_tag`.
261
- */
261
+ * Recovers from a specific tagged error by `_tag`.
262
+ */
262
263
  catchTag: <const Tag extends TagsOf<E>, R extends Result<unknown, unknown>>(tag: Tag, f: (error: ErrorForTag$1<E, Tag>) => R) => Result<T | InferOkTypes<R>, ExcludeTag<E, Tag> | InferErrTypes<R>>;
263
264
  /**
264
- * Recovers from multiple tagged errors by `_tag`.
265
- */
265
+ * Recovers from multiple tagged errors by `_tag`.
266
+ */
266
267
  catchTags: <const Handlers extends object>(handlers: Handlers & ResultCatchTagHandlers<E, Handlers>) => Result<T | InferOkTypes<CatchTagHandlerResult<Handlers>>, ExcludeTag<E, keyof Handlers & string> | InferErrTypes<CatchTagHandlerResult<Handlers>>>;
267
268
  /**
268
- * Recovers from a nested tagged `reason` on a specific tagged error.
269
- */
269
+ * Recovers from a nested tagged `reason` on a specific tagged error.
270
+ */
270
271
  catchReason: <const ErrorTag extends TagsWithReasonOf<E>, const ReasonTag extends ReasonTagsOf<E, ErrorTag>, R extends Result<unknown, unknown>>(errorTag: ErrorTag, reasonTag: ReasonTag, f: (reason: ReasonForTag<E, ErrorTag, ReasonTag>, error: ErrorForTag$1<E, ErrorTag>) => R) => Result<T | InferOkTypes<R>, ExcludeReasonTag<E, ErrorTag, ReasonTag> | InferErrTypes<R>>;
271
272
  /**
272
- * Recovers from multiple nested tagged `reason` variants on a specific tagged error.
273
- */
273
+ * Recovers from multiple nested tagged `reason` variants on a specific tagged error.
274
+ */
274
275
  catchReasons: <const ErrorTag extends TagsWithReasonOf<E>, const Handlers extends object>(errorTag: ErrorTag, handlers: Handlers & ResultCatchReasonHandlers<E, ErrorTag, Handlers>) => Result<T | InferOkTypes<CatchReasonHandlerResult<Handlers>>, ExcludeReasonTag<E, ErrorTag, keyof Handlers & string> | InferErrTypes<CatchReasonHandlerResult<Handlers>>>;
275
276
  /**
276
- * Moves the nested `reason` of a tagged error into the Result error channel.
277
- */
277
+ * Moves the nested `reason` of a tagged error into the Result error channel.
278
+ */
278
279
  unwrapReason: <const ErrorTag extends TagsWithReasonOf<E>>(errorTag: ErrorTag) => Result<T, ExcludeTag<E, ErrorTag> | ReasonsOf<E, ErrorTag>>;
279
280
  /**
280
- * Chains an async fallible operation from the Ok value.
281
- */
281
+ * Chains an async fallible operation from the Ok value.
282
+ */
282
283
  asyncAndThen: <X, Y>(f: (t: T) => ResultAsync<X, Y>) => ResultAsync<X, E | Y>;
283
284
  /**
284
- * Maps the Ok value with an async function and returns a `ResultAsync`.
285
- */
285
+ * Maps the Ok value with an async function and returns a `ResultAsync`.
286
+ */
286
287
  asyncMap: <X>(f: (t: T) => Promise<X>) => ResultAsync<X, E>;
287
288
  /**
288
- * Converts this Result into a plain value by handling both Ok and Err.
289
- */
289
+ * Converts this Result into a plain value by handling both Ok and Err.
290
+ */
290
291
  match: {
291
292
  <A, B = A>(handlers: MatchHandlers$1<T, E, A, B>): A | B;
292
293
  <A, B = A>(fnOk: MatchOkHandler<T, A>, fnErr: MatchErrorHandler<E, B>): A | B;
293
294
  };
294
295
  /**
295
- * Converts this Result into a plain value with exhaustive tagged-error handlers.
296
- */
296
+ * Converts this Result into a plain value with exhaustive tagged-error handlers.
297
+ */
297
298
  matchTags: <A, const Handlers extends object>(fnOk: (t: T) => A, handlers: Handlers & MatchTagHandlers<E, Handlers>) => A | MatchTagHandlerResult<Handlers>;
298
299
  /**
299
- * Converts this Result into a plain value with partial tagged-error handlers and a fallback.
300
- */
300
+ * Converts this Result into a plain value with partial tagged-error handlers and a fallback.
301
+ */
301
302
  matchTagsPartial: <A, B, const Handlers extends object>(fnOk: (t: T) => A, handlers: Handlers & PartialMatchTagHandlers<E, Handlers>, fallback: (error: E) => B) => A | MatchTagHandlerResult<Handlers> | B;
302
303
  /**
303
- * Pipes this Result through reusable transformation functions.
304
- */
304
+ * Pipes this Result through reusable transformation functions.
305
+ */
305
306
  pipe: {
306
307
  <A>(ab: PipeFn<Result<T, E>, A>): A;
307
308
  <A, B>(ab: PipeFn<Result<T, E>, A>, bc: PipeFn<A, B>): B;
308
309
  <A, B, C>(ab: PipeFn<Result<T, E>, A>, bc: PipeFn<A, B>, cd: PipeFn<B, C>): C;
309
310
  };
310
311
  /**
311
- * Runs a side effect with the Ok or Err value and returns this same Result.
312
- *
313
- * Exceptions thrown by the side effect are swallowed.
314
- */
312
+ * Runs a side effect with the Ok or Err value and returns this same Result.
313
+ *
314
+ * Exceptions thrown by the side effect are swallowed.
315
+ */
315
316
  log: (fn: (t?: T, e?: E) => void) => this;
316
317
  /**
317
- * Runs a side effect only when this result is Ok and returns this same Result.
318
- *
319
- * Exceptions thrown by the side effect are swallowed.
320
- */
318
+ * Runs a side effect only when this result is Ok and returns this same Result.
319
+ *
320
+ * Exceptions thrown by the side effect are swallowed.
321
+ */
321
322
  tap: (fn: (t: T) => void) => this;
322
323
  /**
323
- * Runs a side effect only when this result is Err and returns this same Result.
324
- *
325
- * Exceptions thrown by the side effect are swallowed.
326
- */
324
+ * Runs a side effect only when this result is Err and returns this same Result.
325
+ *
326
+ * Exceptions thrown by the side effect are swallowed.
327
+ */
327
328
  tapError: (fn: (e: E) => void) => this;
328
329
  /**
329
- * Attaches a synchronous disposal finalizer to this Result.
330
- */
330
+ * Attaches a synchronous disposal finalizer to this Result.
331
+ */
331
332
  toDisposable: (f: ResultFinalizer<T, E>) => DisposableResult<T, E>;
332
333
  /**
333
- * Returns the Ok value or throws the Err value.
334
- *
335
- * Use this at final application boundaries after the error channel has been modeled.
336
- */
334
+ * Returns the Ok value or throws the Err value.
335
+ *
336
+ * Use this at final application boundaries after the error channel has been modeled.
337
+ */
337
338
  unwrapOrThrow: () => T;
338
339
  /**
339
- * Enables `yield* result` inside `safeTry` generators.
340
- */
340
+ * Enables `yield* result` inside `safeTry` generators.
341
+ */
341
342
  [Symbol.iterator]: () => Generator<Result<never, E>, T>;
342
343
  /**
343
- * Compatibility generator for `safeTry`. Prefer `yield* result` in new code.
344
- */
344
+ * Compatibility generator for `safeTry`. Prefer `yield* result` in new code.
345
+ */
345
346
  safeUnwrap: () => Generator<Result<never, E>, T>;
346
347
  }
348
+ /** Successful `Result` variant carrying a value of type `T`. */
347
349
  interface OkResult<T, E> extends ResultOperations<T, E> {
348
350
  /**
349
- * Ok value carried by this result.
350
- */
351
+ * Ok value carried by this result.
352
+ */
351
353
  readonly value: T;
352
354
  }
355
+ /** Failed `Result` variant carrying an error of type `E`. */
353
356
  interface ErrResult<T, E> extends ResultOperations<T, E> {
354
357
  /**
355
- * Err value carried by this result.
356
- */
358
+ * Err value carried by this result.
359
+ */
357
360
  readonly error: E;
358
361
  }
362
+ /** Success-or-failure value with explicit Ok and Err channels. */
359
363
  type Result<T, E> = OkResult<T, E> | ErrResult<T, E>;
364
+ /** `Result` convention that restricts the error channel to real `Error` instances. */
360
365
  type StrictResult<T, E extends Error = Error> = Result<T, E>;
361
366
  /**
362
- * Object form accepted by `tryResult`.
363
- *
364
- * Use this form when named `try` and `catch` fields make a synchronous boundary easier to read.
365
- */
367
+ * Object form accepted by `tryResult`.
368
+ *
369
+ * Use this form when named `try` and `catch` fields make a synchronous boundary easier to read.
370
+ */
366
371
  interface TryResultOptions<T, E = unknown> {
367
372
  /**
368
- * Runs the synchronous work whose thrown value should become `Err<E>`.
369
- */
373
+ * Runs the synchronous work whose thrown value should become `Err<E>`.
374
+ */
370
375
  readonly try: () => Exclude<T, Promise<unknown>>;
371
376
  /**
372
- * Converts a thrown `unknown` cause into the typed Resultar error channel.
373
- *
374
- * If omitted, the error channel is `unknown`.
375
- */
377
+ * Converts a thrown `unknown` cause into the typed Resultar error channel.
378
+ *
379
+ * If omitted, the error channel is `unknown`.
380
+ */
376
381
  readonly catch?: (e: unknown) => E;
377
382
  }
383
+ /** Object-form synchronous generator workflow accepted by `safeTry`. */
378
384
  interface SafeTryOptions<YieldErr extends Result<never, unknown>, GeneratorReturnResult extends Result<unknown, unknown>, CatchErr = never> {
379
385
  /**
380
- * Generator body evaluated by `safeTry`.
381
- *
382
- * Use `yield* result` to unwrap Resultar values and short-circuit on Err.
383
- */
386
+ * Generator body evaluated by `safeTry`.
387
+ *
388
+ * Use `yield* result` to unwrap Resultar values and short-circuit on Err.
389
+ */
384
390
  readonly try: () => Generator<YieldErr, GeneratorReturnResult>;
385
391
  /**
386
- * Converts synchronous throws from the generator setup into the Result error channel.
387
- */
392
+ * Converts synchronous throws from the generator setup into the Result error channel.
393
+ */
388
394
  readonly catch?: (e: unknown) => CatchErr;
389
395
  }
396
+ /** Object-form asynchronous generator workflow accepted by `safeTry`. */
390
397
  interface SafeTryAsyncOptions<YieldErr extends Result<never, unknown>, GeneratorReturnResult extends Result<unknown, unknown>, CatchErr = never> {
391
398
  /**
392
- * Async generator body evaluated by `safeTry`.
393
- *
394
- * Use `yield* result` or `yield* resultAsync` to unwrap Resultar values and short-circuit on Err.
395
- */
399
+ * Async generator body evaluated by `safeTry`.
400
+ *
401
+ * Use `yield* result` or `yield* resultAsync` to unwrap Resultar values and short-circuit on Err.
402
+ */
396
403
  readonly try: () => AsyncGenerator<YieldErr, GeneratorReturnResult>;
397
404
  /**
398
- * Converts synchronous throws or async rejections from the generator setup into the ResultAsync
399
- * error channel.
400
- */
405
+ * Converts synchronous throws or async rejections from the generator setup into the ResultAsync
406
+ * error channel.
407
+ */
401
408
  readonly catch?: (e: unknown) => CatchErr;
402
409
  }
403
410
  interface ResultStatic {
404
411
  /**
405
- * Runtime `instanceof Result` support for Ok and Err values.
406
- */
412
+ * Runtime `instanceof Result` support for Ok and Err values.
413
+ */
407
414
  [Symbol.hasInstance]: (value: unknown) => boolean;
408
415
  /**
409
- * Runs synchronous work and captures thrown values into a Result.
410
- *
411
- * Compatibility alias. Prefer the top-level `tryResult` helper in new code.
412
- */
416
+ * Runs synchronous work and captures thrown values into a Result.
417
+ *
418
+ * Compatibility alias. Prefer the top-level `tryResult` helper in new code.
419
+ */
413
420
  tryCatch: <T, E>(this: void, fn: () => Exclude<T, Promise<unknown>>, errorFn?: (e: unknown) => E) => Result<T, E>;
414
421
  /**
415
- * Wraps a throwing synchronous function so every later call returns a Result.
416
- */
422
+ * Wraps a throwing synchronous function so every later call returns a Result.
423
+ */
417
424
  fromThrowable: <Fn extends (...args: readonly any[]) => unknown, E>(this: void, fn: Fn, errorFn?: (e: any) => E) => (...args: Parameters<Fn>) => Result<ReturnType<Fn>, E>;
418
425
  /**
419
- * Creates an Ok result.
420
- */
426
+ * Creates an Ok result.
427
+ */
421
428
  ok: {
422
429
  <T, E = never>(this: void, value: T): OkResult<T, E>;
423
430
  <E = never>(this: void, value: void): OkResult<void, E>;
424
431
  };
425
432
  /**
426
- * Creates an Ok result with `undefined`.
427
- */
433
+ * Creates an Ok result with `undefined`.
434
+ */
428
435
  unit: <E = never>(this: void) => Result<undefined, E>;
429
436
  /**
430
- * Creates an Err result.
431
- */
437
+ * Creates an Err result.
438
+ */
432
439
  err: {
433
440
  <T = never, E extends string = string>(this: void, err: E): ErrResult<T, E>;
434
441
  <T = never, E = unknown>(this: void, err: E): ErrResult<T, E>;
435
442
  <T = never>(this: void, err: void): ErrResult<T, void>;
436
443
  };
437
444
  /**
438
- * Combines many Result values and stops at the first Err.
439
- *
440
- * Arrays return an Ok array, records return an Ok record with the same keys, and iterables return
441
- * an Ok readonly array.
442
- */
445
+ * Combines many Result values and stops at the first Err.
446
+ *
447
+ * Arrays return an Ok array, records return an Ok record with the same keys, and iterables return
448
+ * an Ok readonly array.
449
+ */
443
450
  combine: {
444
451
  <T extends readonly [Result<unknown, unknown>, ...Result<unknown, unknown>[]]>(this: void, resultList: T): CombineResults<T>;
445
452
  <T extends readonly Result<unknown, unknown>[]>(this: void, resultList: T): CombineResults<T>;
@@ -447,8 +454,8 @@ interface ResultStatic {
447
454
  <R extends Result<unknown, unknown>>(this: void, results: Iterable<R>): CombineResultsIterable<R>;
448
455
  };
449
456
  /**
450
- * Combines many Result values and collects every Err instead of stopping at the first one.
451
- */
457
+ * Combines many Result values and collects every Err instead of stopping at the first one.
458
+ */
452
459
  combineWithAllErrors: {
453
460
  <T extends readonly [Result<unknown, unknown>, ...Result<unknown, unknown>[]]>(this: void, resultList: T): CombineResultsWithAllErrorsArray<T>;
454
461
  <T extends readonly Result<unknown, unknown>[]>(this: void, resultList: T): CombineResultsWithAllErrorsArray<T>;
@@ -456,51 +463,51 @@ interface ResultStatic {
456
463
  <R extends Result<unknown, unknown>>(this: void, results: Iterable<R>): CombineResultsIterableWithAllErrors<R>;
457
464
  };
458
465
  /**
459
- * Validates many Result values and collects every Err.
460
- *
461
- * When passed items plus a mapper, the mapper must return a Result for each item.
462
- */
466
+ * Validates many Result values and collects every Err.
467
+ *
468
+ * When passed items plus a mapper, the mapper must return a Result for each item.
469
+ */
463
470
  validateAll: {
464
471
  <T extends readonly [Result<unknown, unknown>, ...Result<unknown, unknown>[]]>(this: void, resultList: T): CombineResultsWithAllErrorsArray<T>;
465
472
  <T extends readonly Result<unknown, unknown>[]>(this: void, resultList: T): CombineResultsWithAllErrorsArray<T>;
466
473
  <Item, R extends Result<unknown, unknown>>(this: void, items: Iterable<Item>, f: (value: Item, index: number) => R): ResultValidatedAll<R>;
467
474
  };
468
475
  /**
469
- * Combines exactly two Result values into an Ok tuple or the first Err.
470
- */
476
+ * Combines exactly two Result values into an Ok tuple or the first Err.
477
+ */
471
478
  zip: <Left extends Result<unknown, unknown>, Right extends Result<unknown, unknown>>(this: void, left: Left, right: Right) => ResultZipped<Left, Right>;
472
479
  /**
473
- * Runs candidates until the first Ok and returns the last Err if every candidate fails.
474
- */
480
+ * Runs candidates until the first Ok and returns the last Err if every candidate fails.
481
+ */
475
482
  firstSuccessOf: <Candidates extends Iterable<ResultCandidate>>(this: void, candidates: Candidates) => FirstSuccessOf<Candidates>;
476
483
  /**
477
- * Chooses one of two Result branches from a boolean or Result boolean condition.
478
- */
484
+ * Chooses one of two Result branches from a boolean or Result boolean condition.
485
+ */
479
486
  if: {
480
487
  <OnTrue extends Result<unknown, unknown>, OnFalse extends Result<unknown, unknown>>(this: void, condition: ResultBooleanCondition, options: ResultIfOptions<OnTrue, OnFalse>): ResultIf<never, OnTrue, OnFalse>;
481
488
  <Condition extends Result<boolean, unknown>, OnTrue extends Result<unknown, unknown>, OnFalse extends Result<unknown, unknown>>(this: void, condition: Condition, options: ResultIfOptions<OnTrue, OnFalse>): ResultIf<InferErrTypes<Condition>, OnTrue, OnFalse>;
482
489
  };
483
490
  /**
484
- * Runs `body` only when the condition is true; otherwise returns Ok(undefined).
485
- */
491
+ * Runs `body` only when the condition is true; otherwise returns Ok(undefined).
492
+ */
486
493
  when: <R extends Result<unknown, unknown>>(this: void, condition: ResultBooleanCondition, body: () => R) => ResultWhen<R>;
487
494
  /**
488
- * Runs `body` only when a Result boolean condition is Ok(true).
489
- */
495
+ * Runs `body` only when a Result boolean condition is Ok(true).
496
+ */
490
497
  whenResult: <Condition extends Result<boolean, unknown>, R extends Result<unknown, unknown>>(this: void, condition: Condition, body: () => R) => ResultWhenWithCondition<Condition, R>;
491
498
  /**
492
- * Runs `body` only when the condition is false; otherwise returns Ok(undefined).
493
- */
499
+ * Runs `body` only when the condition is false; otherwise returns Ok(undefined).
500
+ */
494
501
  unless: <R extends Result<unknown, unknown>>(this: void, condition: ResultBooleanCondition, body: () => R) => ResultWhen<R>;
495
502
  /**
496
- * Runs `body` only when a Result boolean condition is Ok(false).
497
- */
503
+ * Runs `body` only when a Result boolean condition is Ok(false).
504
+ */
498
505
  unlessResult: <Condition extends Result<boolean, unknown>, R extends Result<unknown, unknown>>(this: void, condition: Condition, body: () => R) => ResultWhenWithCondition<Condition, R>;
499
506
  /**
500
- * Repeats a Result-producing body while a condition holds.
501
- *
502
- * Use `discard: true` when only failure matters and collected Ok values are not needed.
503
- */
507
+ * Repeats a Result-producing body while a condition holds.
508
+ *
509
+ * Use `discard: true` when only failure matters and collected Ok values are not needed.
510
+ */
504
511
  loop: {
505
512
  <State, BodyState extends State, R extends Result<unknown, unknown>>(this: void, initial: State, options: ResultLoopOptions<State, BodyState, R>): ResultLoopCollected<R>;
506
513
  <State, R extends Result<unknown, unknown>>(this: void, initial: State, options: ResultLoopBooleanOptions<State, R>): ResultLoopCollected<R>;
@@ -508,79 +515,80 @@ interface ResultStatic {
508
515
  <State, R extends Result<unknown, unknown>>(this: void, initial: State, options: ResultLoopBooleanDiscardOptions<State, R>): ResultLoopDiscarded<R>;
509
516
  };
510
517
  /**
511
- * Repeatedly transforms state with a Result-producing body until the condition fails.
512
- */
518
+ * Repeatedly transforms state with a Result-producing body until the condition fails.
519
+ */
513
520
  iterate: {
514
521
  <State, BodyState extends WidenLiteral$1<State>, R extends Result<WidenLiteral$1<State>, unknown>>(this: void, initial: State, options: ResultIterateOptions<WidenLiteral$1<State>, BodyState, R>): ResultIterated<WidenLiteral$1<State>, R>;
515
522
  <State, R extends Result<WidenLiteral$1<State>, unknown>>(this: void, initial: State, options: ResultIterateBooleanOptions<WidenLiteral$1<State>, R>): ResultIterated<WidenLiteral$1<State>, R>;
516
523
  };
517
524
  /**
518
- * Runs a Result-producing mapper for each item.
519
- *
520
- * Use `discard: true` when only failure matters and collected Ok values are not needed.
521
- */
525
+ * Runs a Result-producing mapper for each item.
526
+ *
527
+ * Use `discard: true` when only failure matters and collected Ok values are not needed.
528
+ */
522
529
  forEach: {
523
530
  <Item, R extends Result<unknown, unknown>>(this: void, items: Iterable<Item>, f: (value: Item, index: number) => R, options?: ResultForEachOptions): ResultForEachCollected<R>;
524
531
  <Item, R extends Result<unknown, unknown>>(this: void, items: Iterable<Item>, f: (value: Item, index: number) => R, options: ResultForEachDiscardOptions): ResultForEachDiscarded<R>;
525
532
  };
526
533
  }
534
+ /** Static helpers for creating, combining, and iterating over Result values. */
527
535
  declare const Result: ResultStatic;
528
536
  /**
529
- * A `Disposable` is an object that has a `dispose` method that can be used to
530
- * clean up resources.
531
- */
537
+ * A `Disposable` is an object that has a `dispose` method that can be used to
538
+ * clean up resources.
539
+ */
532
540
  declare class DisposableResult<T, E> implements Resultable<T, E>, Disposable {
533
541
  private disposed;
534
542
  private readonly finalizer;
535
543
  /**
536
- * Wrapped Result value.
537
- */
544
+ * Wrapped Result value.
545
+ */
538
546
  readonly result: Result<T, E>;
539
547
  /**
540
- * Creates a disposable wrapper around a Result.
541
- */
548
+ * Creates a disposable wrapper around a Result.
549
+ */
542
550
  constructor(result: Result<T, E>, finalizer: ResultFinalizer<T, E>);
543
551
  /**
544
- * Ok value when present, otherwise undefined cast to `T` for compatibility.
545
- */
552
+ * Ok value when present, otherwise undefined cast to `T` for compatibility.
553
+ */
546
554
  get value(): T;
547
555
  /**
548
- * Err value when present, otherwise undefined cast to `E` for compatibility.
549
- */
556
+ * Err value when present, otherwise undefined cast to `E` for compatibility.
557
+ */
550
558
  get error(): E;
551
559
  /**
552
- * Delegates to the wrapped Result `_unsafeUnwrap`.
553
- */
560
+ * Delegates to the wrapped Result `_unsafeUnwrap`.
561
+ */
554
562
  _unsafeUnwrap(config?: ErrorConfig): T;
555
563
  /**
556
- * Delegates to the wrapped Result `_unsafeUnwrapErr`.
557
- */
564
+ * Delegates to the wrapped Result `_unsafeUnwrapErr`.
565
+ */
558
566
  _unsafeUnwrapErr(config?: ErrorConfig): E;
559
567
  /**
560
- * Returns whether the wrapped Result is Ok.
561
- */
568
+ * Returns whether the wrapped Result is Ok.
569
+ */
562
570
  isOk(): boolean;
563
571
  /**
564
- * Returns whether the wrapped Result is Err.
565
- */
572
+ * Returns whether the wrapped Result is Err.
573
+ */
566
574
  isErr(): boolean;
567
575
  /**
568
- * Returns the wrapped Ok value, or `defaultValue` when Err.
569
- */
576
+ * Returns the wrapped Ok value, or `defaultValue` when Err.
577
+ */
570
578
  unwrapOr<A>(defaultValue: A): T | A;
571
579
  /**
572
- * Runs the finalizer once.
573
- *
574
- * Finalizer exceptions are intentionally swallowed.
575
- */
580
+ * Runs the finalizer once.
581
+ *
582
+ * Finalizer exceptions are intentionally swallowed.
583
+ */
576
584
  [Symbol.dispose](): void;
577
585
  }
578
586
  /**
579
- * Evaluates a synchronous generator and returns the first yielded Err or returned Result.
580
- *
581
- * Inside the generator, use `yield* result` to unwrap Ok values and short-circuit on Err. The object
582
- * form can map thrown setup errors into the Result error channel.
583
- */
587
+ * Evaluates a synchronous generator and returns the first yielded Err or returned Result.
588
+ *
589
+ * Inside the generator, use `yield* result` to unwrap Ok values and short-circuit on Err. The object
590
+ * form can map thrown setup errors into the Result error channel.
591
+ */
584
592
  declare function safeTry<T, E, CatchErr = E>(input: SafeTryOptions<Result<never, E>, Result<T, E>, CatchErr> & {
585
593
  readonly catch: (e: unknown) => CatchErr;
586
594
  }): Result<T, E | CatchErr>;
@@ -590,13 +598,13 @@ declare function safeTry<YieldErr extends Result<never, unknown>, GeneratorRetur
590
598
  }): Result<InferOkTypes<GeneratorReturnResult>, InferErrTypes<YieldErr> | InferErrTypes<GeneratorReturnResult> | CatchErr>;
591
599
  declare function safeTry<YieldErr extends Result<never, unknown>, GeneratorReturnResult extends Result<unknown, unknown>>(input: (() => Generator<YieldErr, GeneratorReturnResult>) | SafeTryOptions<YieldErr, GeneratorReturnResult>): Result<InferOkTypes<GeneratorReturnResult>, InferErrTypes<YieldErr> | InferErrTypes<GeneratorReturnResult>>;
592
600
  /**
593
- * Evaluates an async generator and returns a ResultAsync for the first yielded Err or returned
594
- * Result.
595
- *
596
- * Inside the generator, use `yield* result` or `yield* resultAsync` to unwrap Ok values and
597
- * short-circuit on Err. The object form can map thrown or rejected setup errors into the ResultAsync
598
- * error channel.
599
- */
601
+ * Evaluates an async generator and returns a ResultAsync for the first yielded Err or returned
602
+ * Result.
603
+ *
604
+ * Inside the generator, use `yield* result` or `yield* resultAsync` to unwrap Ok values and
605
+ * short-circuit on Err. The object form can map thrown or rejected setup errors into the ResultAsync
606
+ * error channel.
607
+ */
600
608
  declare function safeTry<T, E, CatchErr = E>(input: SafeTryAsyncOptions<Result<never, E>, Result<T, E>, CatchErr> & {
601
609
  readonly catch: (e: unknown) => CatchErr;
602
610
  }): ResultAsync<T, E | CatchErr>;
@@ -606,64 +614,64 @@ declare function safeTry<YieldErr extends Result<never, unknown>, GeneratorRetur
606
614
  }): ResultAsync<InferOkTypes<GeneratorReturnResult>, InferErrTypes<YieldErr> | InferErrTypes<GeneratorReturnResult> | CatchErr>;
607
615
  declare function safeTry<YieldErr extends Result<never, unknown>, GeneratorReturnResult extends Result<unknown, unknown>>(input: (() => AsyncGenerator<YieldErr, GeneratorReturnResult>) | SafeTryAsyncOptions<YieldErr, GeneratorReturnResult>): ResultAsync<InferOkTypes<GeneratorReturnResult>, InferErrTypes<YieldErr> | InferErrTypes<GeneratorReturnResult>>;
608
616
  /**
609
- * Creates an Ok result.
610
- */
617
+ * Creates an Ok result.
618
+ */
611
619
  declare function ok<T, E = never>(value: T): OkResult<T, E>;
612
620
  declare function ok<E = never>(value: void): OkResult<void, E>;
613
621
  /**
614
- * Creates an Err result.
615
- */
622
+ * Creates an Err result.
623
+ */
616
624
  declare function err<T = never, E extends string = string>(err: E): ErrResult<T, E>;
617
625
  declare function err<T = never, E = unknown>(err: E): ErrResult<T, E>;
618
626
  declare function err<T = never>(err: void): ErrResult<T, void>;
619
627
  /**
620
- * Wraps a throwing synchronous function so every later call returns a Result.
621
- *
622
- * Prefer `tryResult` when you want to run the operation immediately.
623
- */
628
+ * Wraps a throwing synchronous function so every later call returns a Result.
629
+ *
630
+ * Prefer `tryResult` when you want to run the operation immediately.
631
+ */
624
632
  declare const fromThrowable: typeof Result.fromThrowable;
625
633
  /**
626
- * Runs synchronous work and captures thrown values into `Result<T, E>`.
627
- *
628
- * Use `tryResult` at the edge of uncontrolled synchronous code: JSON parsing, environment parsing,
629
- * platform APIs, or third-party functions that may throw. The mapper receives the thrown `unknown`
630
- * cause and returns the typed error for the Resultar channel.
631
- *
632
- * @example
633
- * ```ts
634
- * const config = tryResult(
635
- * () => JSON.parse(input) as Config,
636
- * (cause) => new ParseConfigError({ cause }),
637
- * )
638
- * ```
639
- */
634
+ * Runs synchronous work and captures thrown values into `Result<T, E>`.
635
+ *
636
+ * Use `tryResult` at the edge of uncontrolled synchronous code: JSON parsing, environment parsing,
637
+ * platform APIs, or third-party functions that may throw. The mapper receives the thrown `unknown`
638
+ * cause and returns the typed error for the Resultar channel.
639
+ *
640
+ * @example
641
+ * ```ts
642
+ * const config = tryResult(
643
+ * () => JSON.parse(input) as Config,
644
+ * (cause) => new ParseConfigError({ cause }),
645
+ * )
646
+ * ```
647
+ */
640
648
  declare function tryResult<T, E>(fn: () => Exclude<T, Promise<unknown>>, errorFn: (e: unknown) => E): Result<T, E>;
641
649
  /**
642
- * Captures a synchronous boundary with named `try` and `catch` fields.
643
- *
644
- * This is equivalent to `tryResult(() => ..., toError)`, but it reads better when the boundary has
645
- * a clear domain name or label.
646
- */
650
+ * Captures a synchronous boundary with named `try` and `catch` fields.
651
+ *
652
+ * This is equivalent to `tryResult(() => ..., toError)`, but it reads better when the boundary has
653
+ * a clear domain name or label.
654
+ */
647
655
  declare function tryResult<T, E>(options: TryResultOptions<T, E> & {
648
656
  readonly catch: (e: unknown) => E;
649
657
  }): Result<T, E>;
650
658
  /**
651
- * Runs synchronous work and captures thrown values into `Result<T, unknown>`.
652
- *
653
- * Prefer the overload with a catch mapper in application code so the error channel stays documented.
654
- * This overload is useful while adapting unknown external failures or during migration.
655
- */
659
+ * Runs synchronous work and captures thrown values into `Result<T, unknown>`.
660
+ *
661
+ * Prefer the overload with a catch mapper in application code so the error channel stays documented.
662
+ * This overload is useful while adapting unknown external failures or during migration.
663
+ */
656
664
  declare function tryResult<T>(input: (() => Exclude<T, Promise<unknown>>) | TryResultOptions<T>): Result<T, unknown>;
657
665
  /**
658
- * Creates an Ok result with `undefined`.
659
- */
666
+ * Creates an Ok result with `undefined`.
667
+ */
660
668
  declare function unit<E = never>(): OkResult<undefined, E>;
661
669
  /**
662
- * Runs a `Result` at an application boundary and returns the success value.
663
- *
664
- * If the result is `Err`, this throws the error. Use it at final framework, CLI, test, or bootstrap
665
- * boundaries after the error channel has already been modeled with Resultar.
666
- */
670
+ * Runs a `Result` at an application boundary and returns the success value.
671
+ *
672
+ * If the result is `Err`, this throws the error. Use it at final framework, CLI, test, or bootstrap
673
+ * boundaries after the error channel has already been modeled with Resultar.
674
+ */
667
675
  declare const runSync: <T, E>(result: Result<T, E>) => T;
668
676
  /** Compatibility alias. Prefer `tryResult` in new code. */
669
677
  declare const tryCatch: typeof tryResult;
@@ -672,7 +680,7 @@ type CollectResults<T, Collected extends unknown[] = [], Depth extends number =
672
680
  type Transpose<A, Transposed extends unknown[][] = [], Depth extends number = 10> = A extends [infer T, ...infer Rest] ? T extends [infer L, infer R] ? Transposed extends [infer PL, infer PR] ? PL extends unknown[] ? PR extends unknown[] ? Transpose<Rest, [[...PL, L], [...PR, R]], Prev[Depth]> : never : never : Transpose<Rest, [[L], [R]], Prev[Depth]> : Transposed : Transposed;
673
681
  type Combine<T, Depth extends number = 5> = Transpose<CollectResults<T>, [], Depth> extends [infer L, infer R] ? [UnknownMembersToNever<L>, UnknownMembersToNever<R>] : Transpose<CollectResults<T>, [], Depth> extends [] ? [[], []] : never;
674
682
  type Dedup<T> = T extends Result<infer RL, infer RR> ? Result<RL, RR> : T;
675
- type MemberListOf<T> = ((T extends unknown ? (t: T) => T : never) extends infer U ? (U extends unknown ? (u: U) => unknown : never) extends ((v: infer V) => unknown) ? V : never : never) extends ((_: unknown) => infer W) ? [...MemberListOf<Exclude<T, W>>, W] : [];
683
+ type MemberListOf<T> = ((T extends unknown ? (t: T) => T : never) extends (infer U) ? (U extends unknown ? (u: U) => unknown : never) extends ((v: infer V) => unknown) ? V : never : never) extends ((_: unknown) => infer W) ? [...MemberListOf<Exclude<T, W>>, W] : [];
676
684
  type EmptyArrayToNever<T, NeverArrayToNever extends number = 0> = T extends [] ? never : NeverArrayToNever extends 1 ? T extends [never, ...infer Rest] ? [EmptyArrayToNever<Rest>] extends [never] ? never : T : T : T;
677
685
  type UnknownMembersToNever<T> = T extends [infer H, ...infer R] ? [[unknown] extends [H] ? never : H, ...UnknownMembersToNever<R>] : T;
678
686
  type MembersToUnion<T> = T extends unknown[] ? T[number] : never;
@@ -686,263 +694,266 @@ type CombineResultsWithAllErrorsArray<T extends readonly Result<unknown, unknown
686
694
  //#endregion
687
695
  //#region src/abort-error.d.ts
688
696
  /**
689
- * Standard cancellation error used by ResultAsync retry, race, timeout, and resource helpers.
690
- */
697
+ * Standard cancellation error used by ResultAsync retry, race, timeout, and resource helpers.
698
+ */
691
699
  declare class AbortError extends Error {
692
700
  /**
693
- * Creates an AbortError.
694
- */
701
+ * Creates an AbortError.
702
+ */
695
703
  constructor(message?: string, options?: ErrorOptions);
696
704
  }
697
705
  /**
698
- * Checks whether a value is an AbortError or abort-shaped platform error.
699
- */
706
+ * Checks whether a value is an AbortError or abort-shaped platform error.
707
+ */
700
708
  declare const isAbortError: (value: unknown) => value is AbortError;
701
709
  //#endregion
702
710
  //#region src/result-async.d.ts
703
711
  type ResultAsyncFinalizer<T, E> = (value: T | undefined, error: E | undefined) => void | Promise<void>;
704
712
  /**
705
- * Object form accepted by `tryResultAsync`.
706
- *
707
- * Use this form when named `try` and `catch` fields make an async boundary easier to read, or when
708
- * you want the mapper next to the promise factory.
709
- */
713
+ * Object form accepted by `tryResultAsync`.
714
+ *
715
+ * Use this form when named `try` and `catch` fields make an async boundary easier to read, or when
716
+ * you want the mapper next to the promise factory.
717
+ */
710
718
  interface TryResultAsyncOptions<T, E = unknown> {
711
719
  /**
712
- * Creates the promise whose rejection should become `Err<E>`.
713
- *
714
- * Synchronous throws from this function are also captured.
715
- */
720
+ * Creates the promise whose rejection should become `Err<E>`.
721
+ *
722
+ * Synchronous throws from this function are also captured.
723
+ */
716
724
  readonly try: () => Promise<T>;
717
725
  /**
718
- * Converts a rejected or thrown `unknown` cause into the typed Resultar error channel.
719
- *
720
- * If omitted, the error channel is `unknown`.
721
- */
726
+ * Converts a rejected or thrown `unknown` cause into the typed Resultar error channel.
727
+ *
728
+ * If omitted, the error channel is `unknown`.
729
+ */
722
730
  readonly catch?: (e: unknown) => E;
723
731
  }
732
+ /** Minimal abort-signal contract used by cancellable Resultar operations. */
724
733
  interface ResultAsyncAbortSignal {
725
734
  /**
726
- * Whether the cooperative async operation has been aborted.
727
- */
735
+ * Whether the cooperative async operation has been aborted.
736
+ */
728
737
  readonly aborted: boolean;
729
738
  /**
730
- * Optional abort cause provided by the losing race, timeout, or caller.
731
- */
739
+ * Optional abort cause provided by the losing race, timeout, or caller.
740
+ */
732
741
  readonly reason?: unknown;
733
742
  /**
734
- * Registers an abort listener.
735
- */
743
+ * Registers an abort listener.
744
+ */
736
745
  addEventListener: (type: "abort", listener: () => void, options?: {
737
746
  readonly once?: boolean;
738
747
  }) => void;
739
748
  /**
740
- * Removes an abort listener.
741
- */
749
+ * Removes an abort listener.
750
+ */
742
751
  removeEventListener: (type: "abort", listener: () => void) => void;
743
752
  }
744
753
  /**
745
- * Context passed to `ResultAsync.fromCallback` subscriptions.
746
- */
754
+ * Context passed to `ResultAsync.fromCallback` subscriptions.
755
+ */
747
756
  interface ResultAsyncCallbackContext<T> {
748
757
  /**
749
- * Completes the operation with `Ok(value)`.
750
- */
758
+ * Completes the operation with `Ok(value)`.
759
+ */
751
760
  readonly resolve: (value: T) => void;
752
761
  /**
753
- * Completes the operation with a cause mapped by the subscription's `catch` function.
754
- */
762
+ * Completes the operation with a cause mapped by the subscription's `catch` function.
763
+ */
755
764
  readonly reject: (cause: unknown) => void;
756
765
  /**
757
- * Cooperative cancellation signal for the subscription.
758
- */
766
+ * Cooperative cancellation signal for the subscription.
767
+ */
759
768
  readonly signal: ResultAsyncAbortSignal;
760
769
  }
761
770
  /**
762
- * Synchronous cleanup returned by a `ResultAsync.fromCallback` subscription.
763
- */
771
+ * Synchronous cleanup returned by a `ResultAsync.fromCallback` subscription.
772
+ */
764
773
  type ResultAsyncCallbackCleanup = () => void;
765
774
  /**
766
- * Options for adapting a callback or subscription API into `ResultAsync`.
767
- */
775
+ * Options for adapting a callback or subscription API into `ResultAsync`.
776
+ */
768
777
  interface ResultAsyncFromCallbackOptions<T, E> {
769
778
  /**
770
- * Maps callback failures and synchronous subscription throws into the typed error channel.
771
- */
779
+ * Maps callback failures and synchronous subscription throws into the typed error channel.
780
+ */
772
781
  readonly catch: (cause: unknown) => E;
773
782
  /**
774
- * Optional external signal that cancels the subscription with `AbortError`.
775
- */
783
+ * Optional external signal that cancels the subscription with `AbortError`.
784
+ */
776
785
  readonly signal?: ResultAsyncAbortSignal;
777
786
  /**
778
- * Registers the callback source and optionally returns a synchronous unsubscribe function.
779
- */
787
+ * Registers the callback source and optionally returns a synchronous unsubscribe function.
788
+ */
780
789
  readonly subscribe: (context: ResultAsyncCallbackContext<T>) => ResultAsyncCallbackCleanup | void;
781
790
  }
782
791
  /**
783
- * Concurrency setting for async collection helpers.
784
- *
785
- * Use a number for bounded parallelism or `'unbounded'` when every task may start immediately.
786
- */
792
+ * Concurrency setting for async collection helpers.
793
+ *
794
+ * Use a number for bounded parallelism or `'unbounded'` when every task may start immediately.
795
+ */
787
796
  type ResultAsyncConcurrency = number | "unbounded";
788
797
  type HandlerOk<R> = InferOkTypes<R> | InferAsyncOkTypes<R>;
789
798
  type HandlerErr<R> = InferErrTypes<R> | InferAsyncErrTypes<R>;
790
799
  type IterableElement<T> = T extends Iterable<infer Element> ? Element : never;
791
800
  /**
792
- * Candidate used by `ResultAsync.firstSuccessOf`.
793
- */
801
+ * Candidate used by `ResultAsync.firstSuccessOf`.
802
+ */
794
803
  type ResultAsyncCandidate = () => ResultAsync<unknown, unknown>;
795
804
  type ResultAsyncRecord = Readonly<Record<string, ResultAsync<unknown, unknown>>>;
796
- type CombineResultAsyncsRecord<T extends ResultAsyncRecord> = ResultAsync<{ readonly [Key in keyof T]: InferAsyncOkTypes<T[Key]> }, InferAsyncErrTypes<T[keyof T]>>;
797
- type CombineResultAsyncsRecordWithAllErrors<T extends ResultAsyncRecord> = ResultAsync<{ readonly [Key in keyof T]: InferAsyncOkTypes<T[Key]> }, InferAsyncErrTypes<T[keyof T]>[]>;
805
+ type CombineResultAsyncsRecord<T extends ResultAsyncRecord> = ResultAsync<{ readonly [Key in keyof T]: InferAsyncOkTypes<T[Key]>; }, InferAsyncErrTypes<T[keyof T]>>;
806
+ type CombineResultAsyncsRecordWithAllErrors<T extends ResultAsyncRecord> = ResultAsync<{ readonly [Key in keyof T]: InferAsyncOkTypes<T[Key]>; }, InferAsyncErrTypes<T[keyof T]>[]>;
798
807
  type CombineResultAsyncsIterable<R extends ResultAsync<unknown, unknown>> = ResultAsync<readonly InferAsyncOkTypes<R>[], InferAsyncErrTypes<R>>;
799
808
  type CombineResultAsyncsIterableWithAllErrors<R extends ResultAsync<unknown, unknown>> = ResultAsync<readonly InferAsyncOkTypes<R>[], InferAsyncErrTypes<R>[]>;
800
809
  /**
801
- * Task used by race, timeout, and retry helpers.
802
- *
803
- * The signal lets the task cooperate with cancellation when another task wins or a timeout fires.
804
- */
810
+ * Task used by race, timeout, and retry helpers.
811
+ *
812
+ * The signal lets the task cooperate with cancellation when another task wins or a timeout fires.
813
+ */
805
814
  type ResultAsyncRaceTask<T, E> = (signal: ResultAsyncAbortSignal) => ResultAsync<T, E>;
806
815
  type ResultAsyncRaceTaskOk<Task> = Task extends ResultAsyncRaceTask<infer T, unknown> ? T : never;
807
816
  type ResultAsyncRaceTaskErr<Task> = Task extends ResultAsyncRaceTask<unknown, infer E> ? E : never;
808
817
  type ResultAsyncRaceTasksOk<Tasks extends readonly ResultAsyncRaceTask<unknown, unknown>[]> = ResultAsyncRaceTaskOk<Tasks[number]>;
809
818
  type ResultAsyncRaceTasksErr<Tasks extends readonly ResultAsyncRaceTask<unknown, unknown>[]> = ResultAsyncRaceTaskErr<Tasks[number]>;
819
+ /** Running cancellable task returned by Resultar race helpers. */
810
820
  interface ResultAsyncRaceHandle<T, E> {
811
821
  /**
812
- * Abort signal associated with the running task.
813
- */
822
+ * Abort signal associated with the running task.
823
+ */
814
824
  readonly signal: ResultAsyncAbortSignal;
815
825
  /**
816
- * Aborts the running task with an optional reason.
817
- */
826
+ * Aborts the running task with an optional reason.
827
+ */
818
828
  abort: (reason?: unknown) => void;
819
829
  /**
820
- * Waits for the task to settle as a ResultAsync.
821
- */
830
+ * Waits for the task to settle as a ResultAsync.
831
+ */
822
832
  wait: () => ResultAsync<T, E>;
823
833
  }
824
834
  /**
825
- * Options for `ResultAsync.timeout`.
826
- */
835
+ * Options for `ResultAsync.timeout`.
836
+ */
827
837
  interface ResultAsyncTimeoutOptions<E> {
828
838
  /**
829
- * Creates the typed timeout error when the timeout wins.
830
- */
839
+ * Creates the typed timeout error when the timeout wins.
840
+ */
831
841
  readonly onTimeout: () => E;
832
842
  /**
833
- * Timeout duration in milliseconds.
834
- */
843
+ * Timeout duration in milliseconds.
844
+ */
835
845
  readonly timeoutMs: number;
836
846
  }
837
847
  /**
838
- * Metadata passed to retry predicates, delays, callbacks, and fallback handlers.
839
- */
848
+ * Metadata passed to retry predicates, delays, callbacks, and fallback handlers.
849
+ */
840
850
  interface ResultAsyncRetryContext {
841
851
  /**
842
- * Current attempt number, starting at 1.
843
- */
852
+ * Current attempt number, starting at 0.
853
+ */
844
854
  readonly attempt: number;
845
855
  /**
846
- * Next attempt number if another retry is scheduled.
847
- */
856
+ * Next attempt number if another retry is scheduled.
857
+ */
848
858
  readonly nextAttempt: number;
849
859
  /**
850
- * Number of retries still available after the current failure.
851
- */
860
+ * Number of retries still available after the current failure.
861
+ */
852
862
  readonly retriesRemaining: number;
853
863
  }
854
864
  /**
855
- * Task used by `ResultAsync.retry` and `ResultAsync.retryOrElse`.
856
- */
865
+ * Task used by `ResultAsync.retry` and `ResultAsync.retryOrElse`.
866
+ */
857
867
  type ResultAsyncRetryTask<T, E> = (attempt: number, signal: ResultAsyncAbortSignal) => ResultAsync<T, E>;
858
868
  type ResultAsyncRetryTaskOk<Task> = Task extends ResultAsyncRetryTask<infer T, unknown> ? T : never;
859
869
  type ResultAsyncRetryTaskErr<Task> = Task extends ResultAsyncRetryTask<unknown, infer E> ? E : never;
860
870
  type ResultAsyncRetryDelay = number | ((context: ResultAsyncRetryContext) => number);
871
+ /** Retry policy for `ResultAsync.retry` and related helpers. */
861
872
  interface ResultAsyncRetryOptions<E> {
862
873
  /**
863
- * Delay in milliseconds before retrying. Functions receive retry context.
864
- */
874
+ * Delay in milliseconds before retrying. Functions receive retry context.
875
+ */
865
876
  readonly delayMs?: ResultAsyncRetryDelay;
866
877
  /**
867
- * Randomizes the computed delay by this percentage factor.
868
- *
869
- * For example, `0.5` means 50% below to 50% above the computed delay.
870
- */
878
+ * Randomizes the computed delay by this percentage factor.
879
+ *
880
+ * For example, `0.5` means 50% below to 50% above the computed delay.
881
+ */
871
882
  readonly jittered?: number;
872
883
  /**
873
- * Side effect called after a failed attempt that will be retried.
874
- */
884
+ * Side effect called after a failed attempt that will be retried.
885
+ */
875
886
  readonly onRetry?: (error: E, context: ResultAsyncRetryContext) => void | Promise<void>;
876
887
  /**
877
- * Optional external abort signal for the retry loop.
878
- */
888
+ * Optional external abort signal for the retry loop.
889
+ */
879
890
  readonly signal?: ResultAsyncAbortSignal;
880
891
  /**
881
- * Maximum number of retries after the initial attempt.
882
- */
892
+ * Maximum number of retries after the initial attempt.
893
+ */
883
894
  readonly times: number;
884
895
  /**
885
- * Predicate deciding whether a failure is retryable.
886
- */
896
+ * Predicate deciding whether a failure is retryable.
897
+ */
887
898
  readonly while?: (error: E, context: ResultAsyncRetryContext) => boolean | Promise<boolean>;
888
899
  }
889
900
  /**
890
- * Options for `ResultAsync.retryOrElse`.
891
- */
901
+ * Options for `ResultAsync.retryOrElse`.
902
+ */
892
903
  interface ResultAsyncRetryOrElseOptions<E, F, U> extends ResultAsyncRetryOptions<E> {
893
904
  /**
894
- * Fallback Resultar operation used after retry exhaustion.
895
- */
905
+ * Fallback Resultar operation used after retry exhaustion.
906
+ */
896
907
  readonly orElse: (error: E, context: ResultAsyncRetryContext) => Result<U, F> | ResultAsync<U, F>;
897
908
  }
898
909
  /**
899
- * Acquires a resource for `ResultAsync.withResource`.
900
- */
910
+ * Acquires a resource for `ResultAsync.withResource`.
911
+ */
901
912
  type ResultAsyncResourceAcquire<Resource, E> = (signal: ResultAsyncAbortSignal) => ResultAsync<Resource, E>;
902
913
  /**
903
- * Operation accepted by `ResultAsync.withResource` use/release callbacks.
904
- */
914
+ * Operation accepted by `ResultAsync.withResource` use/release callbacks.
915
+ */
905
916
  type ResultAsyncResourceEffect<T, E> = Result<T, E> | ResultAsync<T, E>;
906
917
  /**
907
- * Uses an acquired resource inside `ResultAsync.withResource`.
908
- */
918
+ * Uses an acquired resource inside `ResultAsync.withResource`.
919
+ */
909
920
  type ResultAsyncResourceUse<Resource, T, E> = (resource: Resource, signal: ResultAsyncAbortSignal) => ResultAsyncResourceEffect<T, E>;
910
921
  /**
911
- * Context passed to resource release callbacks.
912
- */
922
+ * Context passed to resource release callbacks.
923
+ */
913
924
  interface ResultAsyncResourceReleaseContext {
914
925
  /**
915
- * Result produced by the use phase, or undefined when acquisition failed.
916
- */
926
+ * Result produced by the use phase, or undefined when acquisition failed.
927
+ */
917
928
  readonly result: Result<unknown, unknown> | undefined;
918
929
  /**
919
- * Abort signal shared by the resource lifecycle.
920
- */
930
+ * Abort signal shared by the resource lifecycle.
931
+ */
921
932
  readonly signal: ResultAsyncAbortSignal;
922
933
  }
923
934
  /**
924
- * Releases a resource after use, regardless of success or failure.
925
- */
935
+ * Releases a resource after use, regardless of success or failure.
936
+ */
926
937
  type ResultAsyncResourceRelease<Resource> = (resource: Resource, context: ResultAsyncResourceReleaseContext) => ResultAsyncResourceEffect<unknown, unknown> | Promise<void> | void;
927
938
  /**
928
- * Options for `ResultAsync.withResource`.
929
- */
939
+ * Options for `ResultAsync.withResource`.
940
+ */
930
941
  interface ResultAsyncWithResourceOptions<Resource, AcquireError, T, UseError> {
931
942
  /**
932
- * Acquires the resource.
933
- */
943
+ * Acquires the resource.
944
+ */
934
945
  readonly acquire: ResultAsyncResourceAcquire<Resource, AcquireError>;
935
946
  /**
936
- * Releases the resource after use.
937
- */
947
+ * Releases the resource after use.
948
+ */
938
949
  readonly release: ResultAsyncResourceRelease<Resource>;
939
950
  /**
940
- * Optional external abort signal for the full lifecycle.
941
- */
951
+ * Optional external abort signal for the full lifecycle.
952
+ */
942
953
  readonly signal?: ResultAsyncAbortSignal;
943
954
  /**
944
- * Uses the acquired resource.
945
- */
955
+ * Uses the acquired resource.
956
+ */
946
957
  readonly use: ResultAsyncResourceUse<Resource, T, UseError>;
947
958
  }
948
959
  type FirstSuccessOfAsync<Candidates extends Iterable<ResultAsyncCandidate>> = ResultAsync<InferAsyncOkTypes<ReturnType<IterableElement<Candidates>>>, InferAsyncErrTypes<ReturnType<IterableElement<Candidates>>>>;
@@ -1007,467 +1018,469 @@ interface ResultAsyncIfOptions<OnTrue extends ResultAsyncConditional, OnFalse ex
1007
1018
  readonly onFalse: () => OnFalse;
1008
1019
  readonly onTrue: () => OnTrue;
1009
1020
  }
1021
+ /** Async-disposable wrapper that finalizes a `ResultAsync` exactly once. */
1010
1022
  declare class DisposableResultAsync<T, E> implements PromiseLike<Result<T, E>>, AsyncDisposable {
1011
1023
  private readonly innerPromise;
1012
1024
  private readonly finalizer;
1013
1025
  private disposed;
1014
1026
  /**
1015
- * Creates an async disposable wrapper around a ResultAsync promise.
1016
- */
1027
+ * Creates an async disposable wrapper around a ResultAsync promise.
1028
+ */
1017
1029
  constructor(res: Promise<Result<T, E>>, finalizer: ResultAsyncFinalizer<T, E>);
1018
1030
  /**
1019
- * PromiseLike integration. Resolves to the wrapped Result.
1020
- */
1031
+ * PromiseLike integration. Resolves to the wrapped Result.
1032
+ */
1021
1033
  then<A, B>(successCallback?: (res: Result<T, E>) => A | PromiseLike<A>, failureCallback?: (reason: unknown) => B | PromiseLike<B>): PromiseLike<A | B>;
1022
1034
  /**
1023
- * Runs the finalizer once after the wrapped Result resolves.
1024
- *
1025
- * Finalizer exceptions and rejections are intentionally swallowed.
1026
- */
1035
+ * Runs the finalizer once after the wrapped Result resolves.
1036
+ *
1037
+ * Finalizer exceptions and rejections are intentionally swallowed.
1038
+ */
1027
1039
  [Symbol.asyncDispose](): Promise<void>;
1028
1040
  }
1029
1041
  /**
1030
- * Represents an asynchronous Result type that wraps a Promise of a Result<T, E>.
1031
- * This class provides a way to handle asynchronous operations that may succeed with a value of type T
1032
- * or fail with an error of type E.
1033
- *
1034
- * @template T - The type of the success value
1035
- * @template E - The type of the error value
1036
- *
1037
- * @implements {PromiseLike<Result<T, E>>}
1038
- *
1039
- * @example
1040
- * ```typescript
1041
- * // Create a successful async result
1042
- * const okAsync = ResultAsync.okAsync(42);
1043
- *
1044
- * // Create a failed async result
1045
- * const errAsync = ResultAsync.errAsync(new Error("Something went wrong"));
1046
- *
1047
- * // Transform a Promise into a ResultAsync
1048
- * const resultFromPromise = ResultAsync.fromPromise(
1049
- * fetch("https://api.example.com/data"),
1050
- * (error) => new Error(`API call failed: ${error}`)
1051
- * );
1052
- * ```
1053
- *
1054
- * @remarks
1055
- * ResultAsync implements the PromiseLike interface, allowing it to be used with async/await syntax.
1056
- * It provides various utility methods for transforming and combining results, similar to the Result type,
1057
- * but operating in an asynchronous context.
1058
- *
1059
- * The class includes methods for:
1060
- * - Creating ResultAsync instances (okAsync, errAsync, fromPromise, fromCallback)
1061
- * - Transforming values (map, mapErr)
1062
- * - Chaining operations (andThen, orElse)
1063
- * - Error handling (tapError)
1064
- * - Conditional branching (if)
1065
- * - Combining multiple ResultAsync instances (combine, combineWithAllErrors)
1066
- */
1042
+ * Represents an asynchronous Result type that wraps a Promise of a Result<T, E>.
1043
+ * This class provides a way to handle asynchronous operations that may succeed with a value of type T
1044
+ * or fail with an error of type E.
1045
+ *
1046
+ * @template T - The type of the success value
1047
+ * @template E - The type of the error value
1048
+ *
1049
+ * @implements {PromiseLike<Result<T, E>>}
1050
+ *
1051
+ * @example
1052
+ * ```typescript
1053
+ * // Create a successful async result
1054
+ * const okAsync = ResultAsync.okAsync(42);
1055
+ *
1056
+ * // Create a failed async result
1057
+ * const errAsync = ResultAsync.errAsync(new Error("Something went wrong"));
1058
+ *
1059
+ * // Transform a Promise into a ResultAsync
1060
+ * const resultFromPromise = ResultAsync.fromPromise(
1061
+ * fetch("https://api.example.com/data"),
1062
+ * (error) => new Error(`API call failed: ${error}`)
1063
+ * );
1064
+ * ```
1065
+ *
1066
+ * @remarks
1067
+ * ResultAsync implements the PromiseLike interface, allowing it to be used with async/await syntax.
1068
+ * It provides various utility methods for transforming and combining results, similar to the Result type,
1069
+ * but operating in an asynchronous context.
1070
+ *
1071
+ * The class includes methods for:
1072
+ * - Creating ResultAsync instances (okAsync, errAsync, fromPromise, fromCallback)
1073
+ * - Transforming values (map, mapErr)
1074
+ * - Chaining operations (andThen, orElse)
1075
+ * - Error handling (tapError)
1076
+ * - Conditional branching (if)
1077
+ * - Combining multiple ResultAsync instances (combine, combineWithAllErrors)
1078
+ */
1067
1079
  declare class ResultAsync<T, E> extends Pipeable implements PromiseLike<Result<T, E>> {
1068
1080
  /**
1069
- * Returns a ResultAsync instance that is immediately resolved with a Result.ok(value).
1070
- *
1071
- * @param {T} value - The value to be wrapped in a Result.ok.
1072
- * @return {ResultAsync<T, E>} A ResultAsync instance with the given value and error type E.
1073
- */
1081
+ * Returns a ResultAsync instance that is immediately resolved with a Result.ok(value).
1082
+ *
1083
+ * @param {T} value - The value to be wrapped in a Result.ok.
1084
+ * @return {ResultAsync<T, E>} A ResultAsync instance with the given value and error type E.
1085
+ */
1074
1086
  static okAsync<T, E = never>(this: void, value: T): ResultAsync<T, E>;
1075
1087
  static okAsync<E = never>(this: void, value: void): ResultAsync<void, E>;
1076
1088
  /**
1077
- * Returns a ResultAsync that is immediately resolved with a Result.ok(undefined) value.
1078
- *
1079
- * @return {ResultAsync<undefined, E>} A ResultAsync instance with undefined as the value type and E as the error type.
1080
- */
1089
+ * Returns a ResultAsync that is immediately resolved with a Result.ok(undefined) value.
1090
+ *
1091
+ * @return {ResultAsync<undefined, E>} A ResultAsync instance with undefined as the value type and E as the error type.
1092
+ */
1081
1093
  static unitAsync<E = never>(this: void): ResultAsync<undefined, E>;
1082
1094
  /**
1083
- * Returns a ResultAsync instance that is immediately resolved with a Result.err(error).
1084
- *
1085
- * @param {E} error - The error to be wrapped in a Result.err.
1086
- * @return {ResultAsync<T, E>} A ResultAsync instance with the given error and value type T.
1087
- */
1095
+ * Returns a ResultAsync instance that is immediately resolved with a Result.err(error).
1096
+ *
1097
+ * @param {E} error - The error to be wrapped in a Result.err.
1098
+ * @return {ResultAsync<T, E>} A ResultAsync instance with the given error and value type T.
1099
+ */
1088
1100
  static errAsync<T = never, E = unknown>(this: void, err: E): ResultAsync<T, E>;
1089
1101
  static errAsync<T = never>(this: void, err: void): ResultAsync<T, void>;
1090
1102
  /**
1091
- * Creates a ResultAsync from a Promise, catching any errors that occur during its execution.
1092
- *
1093
- * Compatibility alias. Prefer the top-level `tryResultAsync` helper in new code.
1094
- *
1095
- * @param fn - The Promise or a function returning a Promise to be wrapped in a ResultAsync.
1096
- * @param errorFn - Optional function to transform the caught error into a specific error type.
1097
- * If not provided, the original error will be used.
1098
- * @returns A ResultAsync that will resolve to Ok with the promise's value if successful,
1099
- * or Err with either the transformed error (if errorFn is provided) or the original error.
1100
- *
1101
- * New code should use the top-level `tryResultAsync` helper instead.
1102
- */
1103
+ * Creates a ResultAsync from a Promise, catching any errors that occur during its execution.
1104
+ *
1105
+ * Compatibility alias. Prefer the top-level `tryResultAsync` helper in new code.
1106
+ *
1107
+ * @param fn - The Promise or a function returning a Promise to be wrapped in a ResultAsync.
1108
+ * @param errorFn - Optional function to transform the caught error into a specific error type.
1109
+ * If not provided, the original error will be used.
1110
+ * @returns A ResultAsync that will resolve to Ok with the promise's value if successful,
1111
+ * or Err with either the transformed error (if errorFn is provided) or the original error.
1112
+ *
1113
+ * New code should use the top-level `tryResultAsync` helper instead.
1114
+ */
1103
1115
  static tryCatch<T>(this: void, fn: Promise<T> | (() => Promise<T>)): ResultAsync<T, unknown>;
1104
1116
  static tryCatch<T, E>(this: void, fn: Promise<T> | (() => Promise<T>), errorFn: (e: unknown) => E): ResultAsync<T, E>;
1105
1117
  /**
1106
- * Returns a ResultAsync instance that is resolved with a Result.ok(value) or Result.err(error)
1107
- * based on the provided promise.
1108
- *
1109
- * @param {Promise<T>} promise - The promise to be wrapped in a ResultAsync.
1110
- * @return {ResultAsync<T, E>} A ResultAsync instance with the given promise and error type E.
1111
- */
1118
+ * Returns a ResultAsync instance that is resolved with a Result.ok(value) or Result.err(error)
1119
+ * based on the provided promise.
1120
+ *
1121
+ * @param {Promise<T>} promise - The promise to be wrapped in a ResultAsync.
1122
+ * @return {ResultAsync<T, E>} A ResultAsync instance with the given promise and error type E.
1123
+ */
1112
1124
  static fromSafePromise<T, E = never>(this: void, promise: PromiseLike<T>): ResultAsync<T, E>;
1113
1125
  /**
1114
- * Returns a ResultAsync instance that is resolved with a Result.ok(value) or Result.err(error)
1115
- * based on the provided promise.
1116
- *
1117
- * @param {Promise<T>} promise - The promise to be wrapped in a ResultAsync.
1118
- * @param {(e: unknown) => E} errorFn - A function that transforms the error from the promise into the error type E.
1119
- * @return {ResultAsync<T, E>} A ResultAsync instance with the given promise and error type E.
1120
- */
1126
+ * Returns a ResultAsync instance that is resolved with a Result.ok(value) or Result.err(error)
1127
+ * based on the provided promise.
1128
+ *
1129
+ * @param {Promise<T>} promise - The promise to be wrapped in a ResultAsync.
1130
+ * @param {(e: unknown) => E} errorFn - A function that transforms the error from the promise into the error type E.
1131
+ * @return {ResultAsync<T, E>} A ResultAsync instance with the given promise and error type E.
1132
+ */
1121
1133
  static fromPromise<T, E>(this: void, promise: PromiseLike<T>, errorFn: (e: unknown) => E): ResultAsync<T, E>;
1122
1134
  /**
1123
- * Adapts a callback or subscription API into a cancellable ResultAsync.
1124
- *
1125
- * The returned cleanup function runs once after resolve, reject, cancellation, or synchronous
1126
- * subscription failure. Cleanup errors are ignored.
1127
- */
1135
+ * Adapts a callback or subscription API into a cancellable ResultAsync.
1136
+ *
1137
+ * The returned cleanup function runs once after resolve, reject, cancellation, or synchronous
1138
+ * subscription failure. Cleanup errors are ignored.
1139
+ */
1128
1140
  static fromCallback<T, E>(this: void, options: ResultAsyncFromCallbackOptions<T, E>): ResultAsync<T, E | AbortError>;
1129
1141
  /**
1130
- * Combines many ResultAsync values and stops at the first Err.
1131
- *
1132
- * Arrays return an Ok array, records return an Ok record with the same keys, and iterables return
1133
- * an Ok readonly array.
1134
- */
1142
+ * Combines many ResultAsync values and stops at the first Err.
1143
+ *
1144
+ * Arrays return an Ok array, records return an Ok record with the same keys, and iterables return
1145
+ * an Ok readonly array.
1146
+ */
1135
1147
  static combine<T extends readonly [ResultAsync<unknown, unknown>, ...ResultAsync<unknown, unknown>[]]>(this: void, asyncResultList: T): CombineResultAsyncs<T>;
1136
1148
  static combine<T extends readonly ResultAsync<unknown, unknown>[]>(this: void, asyncResultList: T): CombineResultAsyncs<T>;
1137
1149
  static combine<T extends ResultAsyncRecord>(this: void, asyncResultRecord: T): CombineResultAsyncsRecord<T>;
1138
1150
  static combine<R extends ResultAsync<unknown, unknown>>(this: void, asyncResults: Iterable<R>): CombineResultAsyncsIterable<R>;
1139
1151
  /**
1140
- * Combines many ResultAsync values and collects every Err instead of stopping at the first one.
1141
- */
1152
+ * Combines many ResultAsync values and collects every Err instead of stopping at the first one.
1153
+ */
1142
1154
  static combineWithAllErrors<T extends readonly [ResultAsync<unknown, unknown>, ...ResultAsync<unknown, unknown>[]]>(this: void, asyncResultList: T): CombineResultsWithAllErrorsArrayAsync<T>;
1143
1155
  static combineWithAllErrors<T extends readonly ResultAsync<unknown, unknown>[]>(this: void, asyncResultList: T): CombineResultsWithAllErrorsArrayAsync<T>;
1144
1156
  static combineWithAllErrors<T extends ResultAsyncRecord>(this: void, asyncResultRecord: T): CombineResultAsyncsRecordWithAllErrors<T>;
1145
1157
  static combineWithAllErrors<R extends ResultAsync<unknown, unknown>>(this: void, asyncResults: Iterable<R>): CombineResultAsyncsIterableWithAllErrors<R>;
1146
1158
  /**
1147
- * Validates many ResultAsync values and collects every Err.
1148
- *
1149
- * When passed items plus a mapper, the mapper must return a ResultAsync for each item. Use the
1150
- * optional concurrency setting to bound parallel work.
1151
- */
1159
+ * Validates many ResultAsync values and collects every Err.
1160
+ *
1161
+ * When passed items plus a mapper, the mapper must return a ResultAsync for each item. Use the
1162
+ * optional concurrency setting to bound parallel work.
1163
+ */
1152
1164
  static validateAll<T extends readonly [ResultAsync<unknown, unknown>, ...ResultAsync<unknown, unknown>[]]>(this: void, asyncResultList: T): CombineResultsWithAllErrorsArrayAsync<T>;
1153
1165
  static validateAll<T extends readonly ResultAsync<unknown, unknown>[]>(this: void, asyncResultList: T): CombineResultsWithAllErrorsArrayAsync<T>;
1154
1166
  static validateAll<Item, R extends ResultAsync<unknown, unknown>>(this: void, items: Iterable<Item>, f: (value: Item, index: number) => R, options?: ResultAsyncValidateAllOptions): ResultAsyncValidatedAll<R>;
1155
1167
  /**
1156
- * Combines exactly two ResultAsync values into an Ok tuple or the first Err.
1157
- */
1168
+ * Combines exactly two ResultAsync values into an Ok tuple or the first Err.
1169
+ */
1158
1170
  static zip<Left extends ResultAsync<unknown, unknown>, Right extends ResultAsync<unknown, unknown>>(this: void, left: Left, right: Right): ResultAsyncZipped<Left, Right>;
1159
1171
  /**
1160
- * Retries a ResultAsync task according to a typed retry policy.
1161
- *
1162
- * The returned error channel includes the task error and `AbortError`.
1163
- */
1172
+ * Retries a ResultAsync task according to a typed retry policy.
1173
+ *
1174
+ * The returned error channel includes the task error and `AbortError`.
1175
+ */
1164
1176
  static retry<Task extends ResultAsyncRetryTask<unknown, unknown>>(this: void, task: Task, options: ResultAsyncRetryOptions<ResultAsyncRetryTaskErr<Task>>): ResultAsync<ResultAsyncRetryTaskOk<Task>, ResultAsyncRetryTaskErr<Task> | AbortError>;
1165
1177
  /**
1166
- * Retries a ResultAsync task and falls back to another Resultar operation after retry exhaustion.
1167
- */
1178
+ * Retries a ResultAsync task and falls back to another Resultar operation after retry exhaustion.
1179
+ */
1168
1180
  static retryOrElse<Task extends ResultAsyncRetryTask<unknown, unknown>, U, F>(this: void, task: Task, options: ResultAsyncRetryOrElseOptions<ResultAsyncRetryTaskErr<Task>, F, U>): ResultAsync<ResultAsyncRetryTaskOk<Task> | U, F | AbortError>;
1169
1181
  /**
1170
- * Acquires, uses, and releases a resource with cleanup on every path.
1171
- *
1172
- * Release errors are intentionally not part of the success/error channel; model cleanup failures
1173
- * in `use` when they should affect control flow.
1174
- */
1182
+ * Acquires, uses, and releases a resource with cleanup on every path.
1183
+ *
1184
+ * Release errors are intentionally not part of the success/error channel; model cleanup failures
1185
+ * in `use` when they should affect control flow.
1186
+ */
1175
1187
  static withResource<Resource, AcquireError, T, UseError>(this: void, options: ResultAsyncWithResourceOptions<Resource, AcquireError, T, UseError>): ResultAsync<T, AcquireError | UseError | AbortError>;
1176
1188
  /**
1177
- * Races two cooperative ResultAsync tasks and returns the first settled Result.
1178
- */
1189
+ * Races two cooperative ResultAsync tasks and returns the first settled Result.
1190
+ */
1179
1191
  static race<Left extends ResultAsyncRaceTask<unknown, unknown>, Right extends ResultAsyncRaceTask<unknown, unknown>>(this: void, left: Left, right: Right): ResultAsync<ResultAsyncRaceTaskOk<Left> | ResultAsyncRaceTaskOk<Right>, ResultAsyncRaceTaskErr<Left> | ResultAsyncRaceTaskErr<Right>>;
1180
1192
  /**
1181
- * Races multiple cooperative ResultAsync tasks and returns the first settled Result.
1182
- */
1193
+ * Races multiple cooperative ResultAsync tasks and returns the first settled Result.
1194
+ */
1183
1195
  static raceAll<Tasks extends readonly [ResultAsyncRaceTask<unknown, unknown>, ...ResultAsyncRaceTask<unknown, unknown>[]]>(this: void, tasks: Tasks): ResultAsync<ResultAsyncRaceTasksOk<Tasks>, ResultAsyncRaceTasksErr<Tasks>>;
1184
1196
  /**
1185
- * Races two cooperative ResultAsync tasks and returns the first successful Ok.
1186
- *
1187
- * If both fail, the returned error is the final observed Err.
1188
- */
1197
+ * Races two cooperative ResultAsync tasks and returns the first successful Ok.
1198
+ *
1199
+ * If both fail, the returned error is the final observed Err.
1200
+ */
1189
1201
  static raceFirst<Left extends ResultAsyncRaceTask<unknown, unknown>, Right extends ResultAsyncRaceTask<unknown, unknown>>(this: void, left: Left, right: Right): ResultAsync<ResultAsyncRaceTaskOk<Left> | ResultAsyncRaceTaskOk<Right>, ResultAsyncRaceTaskErr<Left> | ResultAsyncRaceTaskErr<Right>>;
1190
1202
  /**
1191
- * Races two cooperative ResultAsync tasks and lets handlers decide what to do when either side
1192
- * settles first.
1193
- *
1194
- * Handlers receive the settled Result and a handle to the still-running opposite task.
1195
- */
1203
+ * Races two cooperative ResultAsync tasks and lets handlers decide what to do when either side
1204
+ * settles first.
1205
+ *
1206
+ * Handlers receive the settled Result and a handle to the still-running opposite task.
1207
+ */
1196
1208
  static raceWith<Left extends ResultAsyncRaceTask<unknown, unknown>, Right extends ResultAsyncRaceTask<unknown, unknown>, OnLeftDone extends ResultAsyncConditional, OnRightDone extends ResultAsyncConditional>(this: void, left: Left, right: Right, handlers: {
1197
1209
  readonly onLeftDone: (result: Result<ResultAsyncRaceTaskOk<Left>, ResultAsyncRaceTaskErr<Left>>, right: ResultAsyncRaceHandle<ResultAsyncRaceTaskOk<Right>, ResultAsyncRaceTaskErr<Right>>) => OnLeftDone;
1198
1210
  readonly onRightDone: (result: Result<ResultAsyncRaceTaskOk<Right>, ResultAsyncRaceTaskErr<Right>>, left: ResultAsyncRaceHandle<ResultAsyncRaceTaskOk<Left>, ResultAsyncRaceTaskErr<Left>>) => OnRightDone;
1199
1211
  }): ResultAsync<HandlerOk<OnLeftDone> | HandlerOk<OnRightDone>, HandlerErr<OnLeftDone> | HandlerErr<OnRightDone>>;
1200
1212
  /**
1201
- * Runs a cooperative ResultAsync task with a typed timeout error.
1202
- */
1213
+ * Runs a cooperative ResultAsync task with a typed timeout error.
1214
+ */
1203
1215
  static timeout<Task extends ResultAsyncRaceTask<unknown, unknown>, TimeoutError>(this: void, task: Task, options: ResultAsyncTimeoutOptions<TimeoutError>): ResultAsync<ResultAsyncRaceTaskOk<Task>, ResultAsyncRaceTaskErr<Task> | TimeoutError>;
1204
1216
  /**
1205
- * Runs async candidates until the first Ok and returns the last Err if every candidate fails.
1206
- */
1217
+ * Runs async candidates until the first Ok and returns the last Err if every candidate fails.
1218
+ */
1207
1219
  static firstSuccessOf<Candidates extends Iterable<ResultAsyncCandidate>>(this: void, candidates: Candidates): FirstSuccessOfAsync<Candidates>;
1208
1220
  /**
1209
- * Chooses one of two Resultar async branches from a boolean or Resultar boolean condition.
1210
- */
1221
+ * Chooses one of two Resultar async branches from a boolean or Resultar boolean condition.
1222
+ */
1211
1223
  static if<OnTrue extends ResultAsyncConditional, OnFalse extends ResultAsyncConditional>(this: void, condition: ResultAsyncBooleanCondition, options: ResultAsyncIfOptions<OnTrue, OnFalse>): ResultAsyncIf<never, OnTrue, OnFalse>;
1212
1224
  static if<Condition extends ResultAsyncConditionResult, OnTrue extends ResultAsyncConditional, OnFalse extends ResultAsyncConditional>(this: void, condition: Condition, options: ResultAsyncIfOptions<OnTrue, OnFalse>): ResultAsyncIf<HandlerErr<Condition>, OnTrue, OnFalse>;
1213
1225
  /**
1214
- * Runs `body` only when the condition is true; otherwise returns Ok(undefined).
1215
- */
1226
+ * Runs `body` only when the condition is true; otherwise returns Ok(undefined).
1227
+ */
1216
1228
  static when<R extends ResultAsyncConditional>(this: void, condition: ResultAsyncBooleanCondition, body: () => R): ResultAsyncWhen<R>;
1217
1229
  /**
1218
- * Runs `body` only when a Resultar boolean condition is Ok(true).
1219
- */
1230
+ * Runs `body` only when a Resultar boolean condition is Ok(true).
1231
+ */
1220
1232
  static whenResult<Condition extends ResultAsyncConditionResult, R extends ResultAsyncConditional>(this: void, condition: Condition, body: () => R): ResultAsyncWhenWithCondition<Condition, R>;
1221
1233
  /**
1222
- * Runs `body` only when the condition is false; otherwise returns Ok(undefined).
1223
- */
1234
+ * Runs `body` only when the condition is false; otherwise returns Ok(undefined).
1235
+ */
1224
1236
  static unless<R extends ResultAsyncConditional>(this: void, condition: ResultAsyncBooleanCondition, body: () => R): ResultAsyncWhen<R>;
1225
1237
  /**
1226
- * Runs `body` only when a Resultar boolean condition is Ok(false).
1227
- */
1238
+ * Runs `body` only when a Resultar boolean condition is Ok(false).
1239
+ */
1228
1240
  static unlessResult<Condition extends ResultAsyncConditionResult, R extends ResultAsyncConditional>(this: void, condition: Condition, body: () => R): ResultAsyncWhenWithCondition<Condition, R>;
1229
1241
  /**
1230
- * Repeats a ResultAsync-producing body while a condition holds.
1231
- *
1232
- * Use `discard: true` when only failure matters and collected Ok values are not needed.
1233
- */
1242
+ * Repeats a ResultAsync-producing body while a condition holds.
1243
+ *
1244
+ * Use `discard: true` when only failure matters and collected Ok values are not needed.
1245
+ */
1234
1246
  static loop<State, BodyState extends State, R extends ResultAsync<unknown, unknown>>(this: void, initial: State, options: ResultAsyncLoopOptions<State, BodyState, R>): ResultAsyncLoopCollected<R>;
1235
1247
  static loop<State, R extends ResultAsync<unknown, unknown>>(this: void, initial: State, options: ResultAsyncLoopBooleanOptions<State, R>): ResultAsyncLoopCollected<R>;
1236
1248
  static loop<State, BodyState extends State, R extends ResultAsync<unknown, unknown>>(this: void, initial: State, options: ResultAsyncLoopDiscardOptions<State, BodyState, R>): ResultAsyncLoopDiscarded<R>;
1237
1249
  static loop<State, R extends ResultAsync<unknown, unknown>>(this: void, initial: State, options: ResultAsyncLoopBooleanDiscardOptions<State, R>): ResultAsyncLoopDiscarded<R>;
1238
1250
  /**
1239
- * Repeatedly transforms state with a ResultAsync-producing body until the condition fails.
1240
- */
1251
+ * Repeatedly transforms state with a ResultAsync-producing body until the condition fails.
1252
+ */
1241
1253
  static iterate<State, BodyState extends WidenLiteral<State>, R extends ResultAsync<WidenLiteral<State>, unknown>>(this: void, initial: State, options: ResultAsyncIterateOptions<WidenLiteral<State>, BodyState, R>): ResultAsyncIterated<WidenLiteral<State>, R>;
1242
1254
  static iterate<State, R extends ResultAsync<WidenLiteral<State>, unknown>>(this: void, initial: State, options: ResultAsyncIterateBooleanOptions<WidenLiteral<State>, R>): ResultAsyncIterated<WidenLiteral<State>, R>;
1243
1255
  /**
1244
- * Runs a ResultAsync-producing mapper for each item.
1245
- *
1246
- * Use `discard: true` when only failure matters and collected Ok values are not needed. Use
1247
- * `concurrency` to bound parallel work.
1248
- */
1256
+ * Runs a ResultAsync-producing mapper for each item.
1257
+ *
1258
+ * Use `discard: true` when only failure matters and collected Ok values are not needed. Use
1259
+ * `concurrency` to bound parallel work.
1260
+ */
1249
1261
  static forEach<Item, R extends ResultAsync<unknown, unknown>>(this: void, items: Iterable<Item>, f: (value: Item, index: number) => R, options?: ResultAsyncForEachOptions): ResultAsyncForEachCollected<R>;
1250
1262
  static forEach<Item, R extends ResultAsync<unknown, unknown>>(this: void, items: Iterable<Item>, f: (value: Item, index: number) => R, options: ResultAsyncForEachDiscardOptions): ResultAsyncForEachDiscarded<R>;
1251
1263
  /**
1252
- * Wraps an async function so every later call returns a ResultAsync.
1253
- *
1254
- * Prefer `tryResultAsync` when you want to run the operation immediately.
1255
- */
1264
+ * Wraps an async function so every later call returns a ResultAsync.
1265
+ *
1266
+ * Prefer `tryResultAsync` when you want to run the operation immediately.
1267
+ */
1256
1268
  static fromThrowable<A extends readonly unknown[], T, E>(this: void, fn: (...args: A) => Promise<T>, errorFn?: (err: unknown) => E): (...args: A) => ResultAsync<T, E>;
1257
1269
  private readonly innerPromise;
1258
1270
  /**
1259
- * Creates a ResultAsync from a Promise that resolves to a Result.
1260
- *
1261
- * Most application code should prefer `tryResultAsync`, `fromPromise`, `okAsync`, or `errAsync`.
1262
- */
1271
+ * Creates a ResultAsync from a Promise that resolves to a Result.
1272
+ *
1273
+ * Most application code should prefer `tryResultAsync`, `fromPromise`, `okAsync`, or `errAsync`.
1274
+ */
1263
1275
  constructor(res: Promise<Result<T, E>>);
1264
1276
  /**
1265
- * PromiseLike integration. Resolves to the underlying `Result<T, E>`.
1266
- *
1267
- * Prefer ResultAsync combinators for application flow; this exists so ResultAsync can be awaited
1268
- * and used by Promise APIs.
1269
- */
1277
+ * PromiseLike integration. Resolves to the underlying `Result<T, E>`.
1278
+ *
1279
+ * Prefer ResultAsync combinators for application flow; this exists so ResultAsync can be awaited
1280
+ * and used by Promise APIs.
1281
+ */
1270
1282
  then<A, B>(successCallback?: (res: Result<T, E>) => A | PromiseLike<A>, failureCallback?: (reason: unknown) => B | PromiseLike<B>): PromiseLike<A | B>;
1271
1283
  /**
1272
- * Maps the Err value while preserving the Ok value.
1273
- */
1284
+ * Maps the Err value while preserving the Ok value.
1285
+ */
1274
1286
  mapErr<U>(f: (t: E) => U | Promise<U>): ResultAsync<T, U>;
1275
1287
  /**
1276
- * Maps the Ok value while preserving the error channel.
1277
- */
1288
+ * Maps the Ok value while preserving the error channel.
1289
+ */
1278
1290
  map<X>(f: (t: T) => X | Promise<X>): ResultAsync<X, E>;
1279
1291
  /**
1280
- * Replaces the Ok value with a constant while preserving the error channel.
1281
- */
1292
+ * Replaces the Ok value with a constant while preserving the error channel.
1293
+ */
1282
1294
  as<X>(value: X): ResultAsync<X, E>;
1283
1295
  /**
1284
- * Keeps the Ok value only when the predicate passes; otherwise returns an Err from `onFalse`.
1285
- */
1296
+ * Keeps the Ok value only when the predicate passes; otherwise returns an Err from `onFalse`.
1297
+ */
1286
1298
  filterOrElse<U extends T, F>(predicate: (value: T) => value is U, onFalse: (value: T) => F | Promise<F>): ResultAsync<U, E | F>;
1287
1299
  filterOrElse<F>(predicate: (value: T) => boolean | Promise<boolean>, onFalse: (value: T) => F | Promise<F>): ResultAsync<T, E | F>;
1288
1300
  /**
1289
- * Chains another fallible sync or async operation from the Ok value.
1290
- *
1291
- * Use this instead of `map` when the callback returns `Result` or `ResultAsync`.
1292
- */
1301
+ * Chains another fallible sync or async operation from the Ok value.
1302
+ *
1303
+ * Use this instead of `map` when the callback returns `Result` or `ResultAsync`.
1304
+ */
1293
1305
  andThen<R extends Result<unknown, unknown>>(f: (t: T) => R): ResultAsync<InferOkTypes<R>, InferErrTypes<R> | E>;
1294
1306
  andThen<R extends ResultAsync<unknown, unknown>>(f: (t: T) => R): ResultAsync<InferAsyncOkTypes<R>, InferAsyncErrTypes<R> | E>;
1295
1307
  andThen<U, F>(f: (t: T) => Result<U, F> | ResultAsync<U, F>): ResultAsync<U, E | F>;
1296
1308
  /**
1297
- * Branches from the Ok value into one of two async fallible Result branches.
1298
- */
1309
+ * Branches from the Ok value into one of two async fallible Result branches.
1310
+ */
1299
1311
  if(fCondition: (t: T) => boolean): {
1300
1312
  true: <X1, Y1>(fTrue: (t: T) => ResultAsync<X1, Y1>) => {
1301
1313
  false: <X2, Y2>(fFalse: (t: T) => ResultAsync<X2, Y2>) => ResultAsync<X1 | X2, Y1 | Y2 | E>;
1302
1314
  };
1303
1315
  };
1304
1316
  /**
1305
- * Recovers from Err with another Result or ResultAsync.
1306
- */
1317
+ * Recovers from Err with another Result or ResultAsync.
1318
+ */
1307
1319
  orElse<R extends Result<unknown, unknown>>(f: (e: E) => R): ResultAsync<InferOkTypes<R> | T, InferErrTypes<R>>;
1308
1320
  orElse<R extends ResultAsync<unknown, unknown>>(f: (e: E) => R): ResultAsync<InferAsyncOkTypes<R> | T, InferAsyncErrTypes<R>>;
1309
1321
  orElse<U, A>(f: (e: E) => Result<U, A> | ResultAsync<U, A>): ResultAsync<U | T, A>;
1310
1322
  /**
1311
- * Recovers from a specific tagged error by `_tag`.
1312
- */
1323
+ * Recovers from a specific tagged error by `_tag`.
1324
+ */
1313
1325
  catchTag<const Tag extends TagsOf<E>, R extends Result<unknown, unknown>>(tag: Tag, f: (error: ErrorForTag$1<E, Tag>) => R): ResultAsync<T | InferOkTypes<R>, ExcludeTag<E, Tag> | InferErrTypes<R>>;
1314
1326
  catchTag<const Tag extends TagsOf<E>, R extends ResultAsync<unknown, unknown>>(tag: Tag, f: (error: ErrorForTag$1<E, Tag>) => R): ResultAsync<T | InferAsyncOkTypes<R>, ExcludeTag<E, Tag> | InferAsyncErrTypes<R>>;
1315
1327
  catchTag<U, F, const Tag extends TagsOf<E>>(tag: Tag, f: (error: ErrorForTag$1<E, Tag>) => Result<U, F> | ResultAsync<U, F>): ResultAsync<T | U, ExcludeTag<E, Tag> | F>;
1316
1328
  /**
1317
- * Recovers from multiple tagged errors by `_tag`.
1318
- */
1329
+ * Recovers from multiple tagged errors by `_tag`.
1330
+ */
1319
1331
  catchTags<const Handlers extends object>(handlers: Handlers & ResultAsyncCatchTagHandlers<E, Handlers>): ResultAsync<T | HandlerOk<CatchTagHandlerResult<Handlers>>, ExcludeTag<E, keyof Handlers & string> | HandlerErr<CatchTagHandlerResult<Handlers>>>;
1320
1332
  /**
1321
- * Recovers from a nested tagged `reason` on a specific tagged error.
1322
- */
1333
+ * Recovers from a nested tagged `reason` on a specific tagged error.
1334
+ */
1323
1335
  catchReason<const ErrorTag extends TagsWithReasonOf<E>, const ReasonTag extends ReasonTagsOf<E, ErrorTag>, R extends Result<unknown, unknown>>(errorTag: ErrorTag, reasonTag: ReasonTag, f: (reason: ReasonForTag<E, ErrorTag, ReasonTag>, error: ErrorForTag$1<E, ErrorTag>) => R): ResultAsync<T | InferOkTypes<R>, ExcludeReasonTag<E, ErrorTag, ReasonTag> | InferErrTypes<R>>;
1324
1336
  catchReason<const ErrorTag extends TagsWithReasonOf<E>, const ReasonTag extends ReasonTagsOf<E, ErrorTag>, R extends ResultAsync<unknown, unknown>>(errorTag: ErrorTag, reasonTag: ReasonTag, f: (reason: ReasonForTag<E, ErrorTag, ReasonTag>, error: ErrorForTag$1<E, ErrorTag>) => R): ResultAsync<T | InferAsyncOkTypes<R>, ExcludeReasonTag<E, ErrorTag, ReasonTag> | InferAsyncErrTypes<R>>;
1325
1337
  catchReason<U, F, const ErrorTag extends TagsWithReasonOf<E>, const ReasonTag extends ReasonTagsOf<E, ErrorTag>>(errorTag: ErrorTag, reasonTag: ReasonTag, f: (reason: ReasonForTag<E, ErrorTag, ReasonTag>, error: ErrorForTag$1<E, ErrorTag>) => Result<U, F> | ResultAsync<U, F>): ResultAsync<T | U, ExcludeReasonTag<E, ErrorTag, ReasonTag> | F>;
1326
1338
  /**
1327
- * Recovers from multiple nested tagged `reason` variants on a specific tagged error.
1328
- */
1339
+ * Recovers from multiple nested tagged `reason` variants on a specific tagged error.
1340
+ */
1329
1341
  catchReasons<const ErrorTag extends TagsWithReasonOf<E>, const Handlers extends object>(errorTag: ErrorTag, handlers: Handlers & ResultAsyncCatchReasonHandlers<E, ErrorTag, Handlers>): ResultAsync<T | HandlerOk<CatchReasonHandlerResult<Handlers>>, ExcludeReasonTag<E, ErrorTag, keyof Handlers & string> | HandlerErr<CatchReasonHandlerResult<Handlers>>>;
1330
1342
  /**
1331
- * Moves the nested `reason` of a tagged error into the ResultAsync error channel.
1332
- */
1343
+ * Moves the nested `reason` of a tagged error into the ResultAsync error channel.
1344
+ */
1333
1345
  unwrapReason<const ErrorTag extends TagsWithReasonOf<E>>(errorTag: ErrorTag): ResultAsync<T, ExcludeTag<E, ErrorTag> | ReasonsOf<E, ErrorTag>>;
1334
1346
  /**
1335
- * Converts this ResultAsync into a Promise of a plain value by handling both Ok and Err.
1336
- */
1347
+ * Converts this ResultAsync into a Promise of a plain value by handling both Ok and Err.
1348
+ */
1337
1349
  match<A, B = A>(handlers: MatchHandlers$1<T, E, A, B>): Promise<A | B>;
1338
1350
  match<A, B = A>(ok: (t: T) => A, fnErr: (e: E) => B): Promise<A | B>;
1339
1351
  /**
1340
- * Converts this ResultAsync into a Promise of a plain value with exhaustive tagged-error handlers.
1341
- */
1352
+ * Converts this ResultAsync into a Promise of a plain value with exhaustive tagged-error handlers.
1353
+ */
1342
1354
  matchTags<A, const Handlers extends object>(ok: (t: T) => A, handlers: Handlers & MatchTagHandlers<E, Handlers>): Promise<A | MatchTagHandlerResult<Handlers>>;
1343
1355
  /**
1344
- * Converts this ResultAsync into a Promise of a plain value with partial tagged-error handlers and
1345
- * a fallback.
1346
- */
1356
+ * Converts this ResultAsync into a Promise of a plain value with partial tagged-error handlers and
1357
+ * a fallback.
1358
+ */
1347
1359
  matchTagsPartial<A, B, const Handlers extends object>(ok: (t: T) => A, handlers: Handlers & PartialMatchTagHandlers<E, Handlers>, fallback: (error: E) => B): Promise<A | MatchTagHandlerResult<Handlers> | B>;
1348
1360
  /**
1349
- * Resolves to the Ok value, or `t` when this ResultAsync is Err.
1350
- */
1361
+ * Resolves to the Ok value, or `t` when this ResultAsync is Err.
1362
+ */
1351
1363
  unwrapOr<A>(t: A): Promise<T | A>;
1352
1364
  /**
1353
- * Resolves to the Ok value or rejects with the Err value.
1354
- *
1355
- * Use this at final application boundaries after the error channel has been modeled.
1356
- */
1365
+ * Resolves to the Ok value or rejects with the Err value.
1366
+ *
1367
+ * Use this at final application boundaries after the error channel has been modeled.
1368
+ */
1357
1369
  unwrapOrThrow(): Promise<T>;
1358
1370
  /**
1359
- * Runs a side effect for either variant and preserves the original async result.
1360
- *
1361
- * For `Ok`, the callback receives `(value, undefined)`.
1362
- * For `Err`, the callback receives `(undefined, error)`.
1363
- * Callback errors and rejected callback promises are intentionally ignored.
1364
- *
1365
- * Use `map`, `mapErr`, `andThen`, or `orElse` when the callback should
1366
- * transform the result.
1367
- */
1371
+ * Runs a side effect for either variant and preserves the original async result.
1372
+ *
1373
+ * For `Ok`, the callback receives `(value, undefined)`.
1374
+ * For `Err`, the callback receives `(undefined, error)`.
1375
+ * Callback errors and rejected callback promises are intentionally ignored.
1376
+ *
1377
+ * Use `map`, `mapErr`, `andThen`, or `orElse` when the callback should
1378
+ * transform the result.
1379
+ */
1368
1380
  log(f: (t?: T, e?: E) => void | Promise<void>): ResultAsync<T, E>;
1369
1381
  /**
1370
- * Runs a side effect only for the `Ok` variant and preserves the original async result.
1371
- *
1372
- * Callback errors and rejected callback promises are intentionally ignored.
1373
- * Use `map` or `andThen` when the callback should transform the value.
1374
- */
1382
+ * Runs a side effect only for the `Ok` variant and preserves the original async result.
1383
+ *
1384
+ * Callback errors and rejected callback promises are intentionally ignored.
1385
+ * Use `map` or `andThen` when the callback should transform the value.
1386
+ */
1375
1387
  tap(f: (t: T) => void | Promise<void>): ResultAsync<T, E>;
1376
1388
  /**
1377
- * Runs a side effect only for the `Err` variant and preserves the original async result.
1378
- *
1379
- * Callback errors and rejected callback promises are intentionally ignored.
1380
- * Use `mapErr` or `orElse` when the callback should transform the error.
1381
- */
1389
+ * Runs a side effect only for the `Err` variant and preserves the original async result.
1390
+ *
1391
+ * Callback errors and rejected callback promises are intentionally ignored.
1392
+ * Use `mapErr` or `orElse` when the callback should transform the error.
1393
+ */
1382
1394
  tapError(f: (e: E) => void | Promise<void>): ResultAsync<T, E>;
1383
1395
  /**
1384
- * Attaches an async disposal finalizer to this ResultAsync.
1385
- */
1396
+ * Attaches an async disposal finalizer to this ResultAsync.
1397
+ */
1386
1398
  toAsyncDisposable(f: ResultAsyncFinalizer<T, E>): DisposableResultAsync<T, E>;
1387
1399
  /**
1388
- * Enables `yield* resultAsync` inside async `safeTry` generators.
1389
- */
1400
+ * Enables `yield* resultAsync` inside async `safeTry` generators.
1401
+ */
1390
1402
  [Symbol.asyncIterator](): AsyncGenerator<Result<never, E>, T>;
1391
1403
  }
1404
+ /** `ResultAsync` convention that restricts the error channel to real `Error` instances. */
1392
1405
  type StrictResultAsync<T, E extends Error = Error> = ResultAsync<T, E>;
1393
1406
  /**
1394
- * Creates an Ok ResultAsync.
1395
- */
1407
+ * Creates an Ok ResultAsync.
1408
+ */
1396
1409
  declare const okAsync: typeof ResultAsync.okAsync;
1397
1410
  /**
1398
- * Creates an Err ResultAsync.
1399
- */
1411
+ * Creates an Err ResultAsync.
1412
+ */
1400
1413
  declare const errAsync: typeof ResultAsync.errAsync;
1401
1414
  /**
1402
- * Adapts a callback or subscription API into a cancellable ResultAsync.
1403
- */
1415
+ * Adapts a callback or subscription API into a cancellable ResultAsync.
1416
+ */
1404
1417
  declare const fromCallback: typeof ResultAsync.fromCallback;
1405
1418
  /**
1406
- * Converts an existing promise into a ResultAsync and maps rejection into a typed Err.
1407
- */
1419
+ * Converts an existing promise into a ResultAsync and maps rejection into a typed Err.
1420
+ */
1408
1421
  declare const fromPromise: typeof ResultAsync.fromPromise;
1409
1422
  /**
1410
- * Converts an existing promise that is expected not to reject into a ResultAsync.
1411
- *
1412
- * Use `fromPromise` or `tryResultAsync` when rejection should become a typed Err.
1413
- */
1423
+ * Converts an existing promise that is expected not to reject into a ResultAsync.
1424
+ *
1425
+ * Use `fromPromise` or `tryResultAsync` when rejection should become a typed Err.
1426
+ */
1414
1427
  declare const fromSafePromise: typeof ResultAsync.fromSafePromise;
1415
1428
  /**
1416
- * Creates an Ok ResultAsync with `undefined`.
1417
- */
1429
+ * Creates an Ok ResultAsync with `undefined`.
1430
+ */
1418
1431
  declare const unitAsync: typeof ResultAsync.unitAsync;
1419
1432
  /**
1420
- * Wraps an async function so every later call returns a ResultAsync.
1421
- */
1433
+ * Wraps an async function so every later call returns a ResultAsync.
1434
+ */
1422
1435
  declare const fromThrowableAsync: typeof ResultAsync.fromThrowable;
1423
1436
  /**
1424
- * Captures a promise or async factory into `ResultAsync<T, E>`.
1425
- *
1426
- * Use `tryResultAsync` at the edge of uncontrolled async code: network calls, file I/O,
1427
- * third-party SDKs, JSON parsing promises, and framework APIs that can reject. The mapper receives
1428
- * the rejected or thrown `unknown` cause and returns the typed error for the Resultar channel.
1429
- *
1430
- * Passing a factory is preferred when creating the promise can throw synchronously.
1431
- *
1432
- * @example
1433
- * ```ts
1434
- * const user = tryResultAsync(
1435
- * () => fetchUser(id),
1436
- * (cause) => new FetchUserError({ cause, id }),
1437
- * )
1438
- * ```
1439
- */
1437
+ * Captures a promise or async factory into `ResultAsync<T, E>`.
1438
+ *
1439
+ * Use `tryResultAsync` at the edge of uncontrolled async code: network calls, file I/O,
1440
+ * third-party SDKs, JSON parsing promises, and framework APIs that can reject. The mapper receives
1441
+ * the rejected or thrown `unknown` cause and returns the typed error for the Resultar channel.
1442
+ *
1443
+ * Passing a factory is preferred when creating the promise can throw synchronously.
1444
+ *
1445
+ * @example
1446
+ * ```ts
1447
+ * const user = tryResultAsync(
1448
+ * () => fetchUser(id),
1449
+ * (cause) => new FetchUserError({ cause, id }),
1450
+ * )
1451
+ * ```
1452
+ */
1440
1453
  declare function tryResultAsync<T, E>(fn: Promise<T> | (() => Promise<T>), errorFn: (e: unknown) => E): ResultAsync<T, E>;
1441
1454
  /**
1442
- * Captures an async boundary with named `try` and `catch` fields.
1443
- *
1444
- * This is equivalent to `tryResultAsync(() => ..., toError)`, but it reads better for reusable
1445
- * infrastructure helpers where the label, task, and mapper live together.
1446
- *
1447
- * @example
1448
- * ```ts
1449
- * const startup = tryResultAsync({
1450
- * try: () => fastify.register(plugin),
1451
- * catch: (cause) => new StartupTaskError({ cause, label: "register plugin" }),
1452
- * })
1453
- * ```
1454
- */
1455
+ * Captures an async boundary with named `try` and `catch` fields.
1456
+ *
1457
+ * This is equivalent to `tryResultAsync(() => ..., toError)`, but it reads better for reusable
1458
+ * infrastructure helpers where the label, task, and mapper live together.
1459
+ *
1460
+ * @example
1461
+ * ```ts
1462
+ * const startup = tryResultAsync({
1463
+ * try: () => fastify.register(plugin),
1464
+ * catch: (cause) => new StartupTaskError({ cause, label: "register plugin" }),
1465
+ * })
1466
+ * ```
1467
+ */
1455
1468
  declare function tryResultAsync<T, E>(options: TryResultAsyncOptions<T, E> & {
1456
1469
  readonly catch: (e: unknown) => E;
1457
1470
  }): ResultAsync<T, E>;
1458
1471
  /**
1459
- * Captures a promise or async factory into `ResultAsync<T, unknown>`.
1460
- *
1461
- * Prefer the overload with a catch mapper in application code so the error channel stays documented.
1462
- * This overload is useful while adapting unknown external failures or during migration.
1463
- */
1472
+ * Captures a promise or async factory into `ResultAsync<T, unknown>`.
1473
+ *
1474
+ * Prefer the overload with a catch mapper in application code so the error channel stays documented.
1475
+ * This overload is useful while adapting unknown external failures or during migration.
1476
+ */
1464
1477
  declare function tryResultAsync<T>(input: Promise<T> | (() => Promise<T>) | TryResultAsyncOptions<T>): ResultAsync<T, unknown>;
1465
1478
  /**
1466
- * Runs a `ResultAsync` at an application boundary and returns the success value.
1467
- *
1468
- * If the result is `Err`, this rejects with the error. Use it at final framework, CLI, test, or
1469
- * bootstrap boundaries after the error channel has already been modeled with Resultar.
1470
- */
1479
+ * Runs a `ResultAsync` at an application boundary and returns the success value.
1480
+ *
1481
+ * If the result is `Err`, this rejects with the error. Use it at final framework, CLI, test, or
1482
+ * bootstrap boundaries after the error channel has already been modeled with Resultar.
1483
+ */
1471
1484
  declare const runPromise: <T, E>(result: ResultAsync<T, E>) => Promise<T>;
1472
1485
  /** Compatibility alias. Prefer `tryResultAsync` in new code. */
1473
1486
  declare const tryCatchAsync: typeof tryResultAsync;
@@ -1480,38 +1493,38 @@ type Writable<T> = T extends readonly unknown[] ? [...T] : T;
1480
1493
  //#endregion
1481
1494
  //#region src/redacted.d.ts
1482
1495
  /**
1483
- * String-like wrapper that hides a sensitive value in messages and JSON output.
1484
- */
1496
+ * String-like wrapper that hides a sensitive value in messages and JSON output.
1497
+ */
1485
1498
  type Redacted<T> = string & {
1486
1499
  /**
1487
- * Internal marker used by `isRedacted`.
1488
- */
1500
+ * Internal marker used by `isRedacted`.
1501
+ */
1489
1502
  readonly __resultarRedacted: true;
1490
1503
  readonly __resultarRedactedType?: T;
1491
1504
  /**
1492
- * Optional label shown as `<redacted:label>`.
1493
- */
1505
+ * Optional label shown as `<redacted:label>`.
1506
+ */
1494
1507
  readonly label: string | undefined;
1495
1508
  /**
1496
- * Serializes to the redacted placeholder.
1497
- */
1509
+ * Serializes to the redacted placeholder.
1510
+ */
1498
1511
  toJSON: () => string;
1499
1512
  /**
1500
- * Converts to the redacted placeholder.
1501
- */
1513
+ * Converts to the redacted placeholder.
1514
+ */
1502
1515
  toString: () => string;
1503
1516
  };
1504
1517
  /**
1505
- * Wraps a sensitive value so tagged-error messages and JSON output show only a placeholder.
1506
- */
1518
+ * Wraps a sensitive value so tagged-error messages and JSON output show only a placeholder.
1519
+ */
1507
1520
  declare const redact: <T>(value: T, label?: string) => Redacted<T>;
1508
1521
  /**
1509
- * Checks whether a value was created by `redact`.
1510
- */
1522
+ * Checks whether a value was created by `redact`.
1523
+ */
1511
1524
  declare const isRedacted: (value: unknown) => value is Redacted<unknown>;
1512
1525
  /**
1513
- * Returns the original sensitive value from a Redacted wrapper.
1514
- */
1526
+ * Returns the original sensitive value from a Redacted wrapper.
1527
+ */
1515
1528
  declare const revealRedacted: <T>(value: Redacted<T>) => T;
1516
1529
  //#endregion
1517
1530
  //#region src/tagged-error.d.ts
@@ -1542,85 +1555,86 @@ type ConstructorProps<Template extends string> = TemplateProps<Template> & {
1542
1555
  type TaggedErrorConstructorArgs<Template extends string> = [ExtractTemplateVariables<Template>] extends [never] ? [props?: {
1543
1556
  readonly cause?: unknown;
1544
1557
  }] : [props: ConstructorProps<Template>];
1558
+ /** Configuration used to create a tagged `Error` class. */
1545
1559
  interface TaggedErrorOptions<Tag extends string, MessageTemplate extends string, Base extends Error = Error> {
1546
1560
  /**
1547
- * Optional base Error class to extend instead of native Error.
1548
- */
1561
+ * Optional base Error class to extend instead of native Error.
1562
+ */
1549
1563
  readonly extends?: ErrorBaseConstructor<Base>;
1550
1564
  /**
1551
- * Message template. `$prop` placeholders are filled from constructor props.
1552
- */
1565
+ * Message template. `$prop` placeholders are filled from constructor props.
1566
+ */
1553
1567
  readonly message?: MessageTemplate;
1554
1568
  /**
1555
- * Stable runtime tag and Error name.
1556
- */
1569
+ * Stable runtime tag and Error name.
1570
+ */
1557
1571
  readonly name: Tag;
1558
1572
  }
1559
1573
  /**
1560
- * Instance type produced by `createTaggedError`.
1561
- */
1574
+ * Instance type produced by `createTaggedError`.
1575
+ */
1562
1576
  type TaggedErrorInstance<Tag extends string, MessageTemplate extends string, Base extends Error = Error> = Base & Readonly<TemplateProps<MessageTemplate>> & {
1563
1577
  /**
1564
- * Stable runtime tag.
1565
- */
1578
+ * Stable runtime tag.
1579
+ */
1566
1580
  readonly _tag: Tag;
1567
1581
  /**
1568
- * Stable identity for grouping errors by tag and message template.
1569
- */
1582
+ * Stable identity for grouping errors by tag and message template.
1583
+ */
1570
1584
  readonly fingerprint: readonly [Tag, MessageTemplate];
1571
1585
  /**
1572
- * Original message template before interpolation.
1573
- */
1586
+ * Original message template before interpolation.
1587
+ */
1574
1588
  readonly messageTemplate: MessageTemplate;
1575
1589
  /**
1576
- * Finds a matching cause in the error cause chain.
1577
- */
1590
+ * Finds a matching cause in the error cause chain.
1591
+ */
1578
1592
  findCause: <T extends Error>(ErrorClass: ErrorClass<T>) => T | undefined;
1579
1593
  /**
1580
- * Serializes the tagged error, metadata, and cause chain.
1581
- */
1594
+ * Serializes the tagged error, metadata, and cause chain.
1595
+ */
1582
1596
  toJSON: () => object;
1583
1597
  };
1584
1598
  /**
1585
- * Class type returned by `createTaggedError`.
1586
- */
1599
+ * Class type returned by `createTaggedError`.
1600
+ */
1587
1601
  type TaggedErrorClass<Tag extends string, MessageTemplate extends string, Base extends Error = Error> = {
1588
1602
  new (...args: TaggedErrorConstructorArgs<MessageTemplate>): TaggedErrorInstance<Tag, MessageTemplate, Base>;
1589
1603
  /**
1590
- * Stable runtime tag.
1591
- */
1604
+ * Stable runtime tag.
1605
+ */
1592
1606
  readonly tag: Tag;
1593
1607
  /**
1594
- * Creates an Err containing this tagged error.
1595
- */
1608
+ * Creates an Err containing this tagged error.
1609
+ */
1596
1610
  err: <This extends new (...args: TaggedErrorConstructorArgs<MessageTemplate>) => Error>(this: This, ...args: TaggedErrorConstructorArgs<MessageTemplate>) => ErrResult<never, ErrorClassInstance<This>>;
1597
1611
  /**
1598
- * Narrows a value to this tagged error class.
1599
- */
1612
+ * Narrows a value to this tagged error class.
1613
+ */
1600
1614
  is: (value: unknown) => value is TaggedErrorInstance<Tag, MessageTemplate, Base>;
1601
1615
  };
1602
1616
  /**
1603
- * Union of members produced by `taggedEnum`.
1604
- */
1617
+ * Union of members produced by `taggedEnum`.
1618
+ */
1605
1619
  type TaggedEnum<Members extends Record<string, object>> = { readonly [Tag in keyof Members]: Readonly<Members[Tag]> & {
1606
1620
  readonly _tag: Tag;
1607
- } }[keyof Members];
1621
+ }; }[keyof Members];
1608
1622
  type TaggedEnumMember<Members extends Record<string, object>, Tag extends keyof Members> = Readonly<Members[Tag]> & {
1609
1623
  readonly _tag: Tag;
1610
1624
  };
1611
1625
  type TaggedEnumConstructor<Members extends Record<string, object>, Tag extends keyof Members> = keyof Members[Tag] extends never ? (props?: Readonly<Members[Tag]>) => TaggedEnumMember<Members, Tag> : (props: Readonly<Members[Tag]>) => TaggedEnumMember<Members, Tag>;
1612
1626
  /**
1613
- * Factory returned by `taggedEnum`.
1614
- */
1615
- type TaggedEnumFactory<Members extends Record<string, object>> = { readonly [Tag in keyof Members]: TaggedEnumConstructor<Members, Tag> } & {
1627
+ * Factory returned by `taggedEnum`.
1628
+ */
1629
+ type TaggedEnumFactory<Members extends Record<string, object>> = { readonly [Tag in keyof Members]: TaggedEnumConstructor<Members, Tag>; } & {
1616
1630
  /**
1617
- * Narrows a value to a tagged enum member.
1618
- */
1631
+ * Narrows a value to a tagged enum member.
1632
+ */
1619
1633
  $is: <Tag extends keyof Members>(tag: Tag, value: unknown) => value is TaggedEnumMember<Members, Tag>;
1620
1634
  /**
1621
- * Exhaustively matches a tagged enum value.
1622
- */
1623
- $match: <ReturnType>(value: TaggedEnum<Members>, handlers: { readonly [Tag in keyof Members]: (value: TaggedEnumMember<Members, Tag>) => ReturnType }) => ReturnType;
1635
+ * Exhaustively matches a tagged enum value.
1636
+ */
1637
+ $match: <ReturnType>(value: TaggedEnum<Members>, handlers: { readonly [Tag in keyof Members]: (value: TaggedEnumMember<Members, Tag>) => ReturnType; }) => ReturnType;
1624
1638
  };
1625
1639
  type TaggedErrorLike = Error & {
1626
1640
  readonly _tag: string;
@@ -1630,7 +1644,7 @@ type ErrorForTag<ErrorType extends Error, Tag extends string> = Extract<ErrorTyp
1630
1644
  readonly _tag: Tag;
1631
1645
  }>;
1632
1646
  type UntaggedError<ErrorType extends Error> = Exclude<ErrorType, TaggedErrorLike>;
1633
- type MatchHandlers<ErrorType extends Error, ReturnType> = { readonly [Tag in TaggedErrorTags<ErrorType>]: (error: ErrorForTag<ErrorType, Tag>) => ReturnType } & ([UntaggedError<ErrorType>] extends [never] ? {
1647
+ type MatchHandlers<ErrorType extends Error, ReturnType> = { readonly [Tag in TaggedErrorTags<ErrorType>]: (error: ErrorForTag<ErrorType, Tag>) => ReturnType; } & ([UntaggedError<ErrorType>] extends [never] ? {
1634
1648
  readonly Error?: (error: Error) => ReturnType;
1635
1649
  } : {
1636
1650
  readonly Error: (error: UntaggedError<ErrorType>) => ReturnType;
@@ -1638,43 +1652,43 @@ type MatchHandlers<ErrorType extends Error, ReturnType> = { readonly [Tag in Tag
1638
1652
  type PartialMatchHandlers<ErrorType extends Error, ReturnType> = Partial<MatchHandlers<ErrorType, ReturnType>>;
1639
1653
  declare const defaultMessageTemplate = "$message";
1640
1654
  /**
1641
- * Narrows a value to native or platform-recognized Error.
1642
- */
1655
+ * Narrows a value to native or platform-recognized Error.
1656
+ */
1643
1657
  declare function isError(value: unknown): value is Error;
1644
1658
  declare function isError<Value>(value: Value): value is Extract<Value, Error>;
1645
1659
  /**
1646
- * Finds the first cause in an Error cause chain that is an instance of `ErrorClass`.
1647
- */
1660
+ * Finds the first cause in an Error cause chain that is an instance of `ErrorClass`.
1661
+ */
1648
1662
  declare const findCause: <T extends Error>(error: Error, ErrorClass: ErrorClass<T>) => T | undefined;
1649
1663
  /**
1650
- * Creates an Error class with a stable `_tag`, typed template props, cause support, and JSON output.
1651
- *
1652
- * Prefer tagged errors for domain failures that travel through Resultar error channels.
1653
- *
1654
- * @example
1655
- * ```ts
1656
- * class UserNotFoundError extends createTaggedError({
1657
- * name: "UserNotFoundError",
1658
- * message: "User $id was not found",
1659
- * }) {}
1660
- * ```
1661
- */
1664
+ * Creates an Error class with a stable `_tag`, typed template props, cause support, and JSON output.
1665
+ *
1666
+ * Prefer tagged errors for domain failures that travel through Resultar error channels.
1667
+ *
1668
+ * @example
1669
+ * ```ts
1670
+ * class UserNotFoundError extends createTaggedError({
1671
+ * name: "UserNotFoundError",
1672
+ * message: "User $id was not found",
1673
+ * }) {}
1674
+ * ```
1675
+ */
1662
1676
  declare function createTaggedError<const Tag extends string, const MessageTemplate extends string = typeof defaultMessageTemplate, Base extends Error = Error>(options: Omit<TaggedErrorOptions<Tag, MessageTemplate, Base>, "message"> & {
1663
1677
  readonly message?: RejectReservedTemplateVariables<MessageTemplate>;
1664
1678
  }): TaggedErrorClass<Tag, MessageTemplate, Base>;
1665
1679
  /**
1666
- * Creates a small tagged-union factory with member constructors, `$is`, and `$match`.
1667
- */
1680
+ * Creates a small tagged-union factory with member constructors, `$is`, and `$match`.
1681
+ */
1668
1682
  declare const taggedEnum: <Members extends Record<string, object>>() => TaggedEnumFactory<Members>;
1669
1683
  /**
1670
- * Matches an Error by tagged `_tag`, with optional native `Error` fallback.
1671
- *
1672
- * Throws the original error when no handler matches.
1673
- */
1684
+ * Matches an Error by tagged `_tag`, with optional native `Error` fallback.
1685
+ *
1686
+ * Throws the original error when no handler matches.
1687
+ */
1674
1688
  declare const matchError: <ErrorType extends Error, ReturnType>(error: ErrorType, handlers: MatchHandlers<ErrorType, ReturnType>) => ReturnType;
1675
1689
  /**
1676
- * Matches an Error by tagged `_tag`, then native `Error`, then the provided fallback.
1677
- */
1690
+ * Matches an Error by tagged `_tag`, then native `Error`, then the provided fallback.
1691
+ */
1678
1692
  declare const matchErrorPartial: <ErrorType extends Error, ReturnType>(error: ErrorType, handlers: PartialMatchHandlers<ErrorType, ReturnType>, fallback: (error: ErrorType) => ReturnType) => ReturnType;
1679
1693
  //#endregion
1680
1694
  export { AbortError, DisposableResult, DisposableResultAsync, type ErrResult, type OkResult, type Redacted, Result, ResultAsync, type ResultAsyncAbortSignal, type ResultAsyncCallbackCleanup, type ResultAsyncCallbackContext, type ResultAsyncConcurrency, type ResultAsyncFromCallbackOptions, type ResultAsyncRaceHandle, type ResultAsyncRaceTask, type ResultAsyncResourceAcquire, type ResultAsyncResourceEffect, type ResultAsyncResourceRelease, type ResultAsyncResourceReleaseContext, type ResultAsyncResourceUse, type ResultAsyncRetryContext, type ResultAsyncRetryOptions, type ResultAsyncRetryOrElseOptions, type ResultAsyncRetryTask, type ResultAsyncTimeoutOptions, type ResultAsyncWithResourceOptions, type ResultOperations, type SafeTryAsyncOptions, type SafeTryOptions, type StrictResult, type StrictResultAsync, type TaggedEnum, type TaggedEnumFactory, type TaggedErrorClass, type TaggedErrorInstance, type TaggedErrorOptions, type TryResultAsyncOptions, type TryResultOptions, createTaggedError, tryResult as default, tryResult as try, tryResult, err, errAsync, findCause, fromCallback, fromPromise, fromSafePromise, fromThrowable, fromThrowableAsync, isAbortError, isError, isRedacted, matchError, matchErrorPartial, ok, okAsync, redact, revealRedacted, runPromise, runSync, safeTry, taggedEnum, tryResultAsync as tryAsync, tryResultAsync, tryCatch, tryCatchAsync, unit, unitAsync };