unthrown 4.0.0 → 4.2.0

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.mts CHANGED
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @internal
7
7
  */
8
- type Prettify<T> = { [K in keyof T]: T[K] } & {};
8
+ type Prettify<T> = { [K in keyof T]: T[K]; } & {};
9
9
  /**
10
10
  * The scope produced by a `bind` / `let` step: `T` with `K` added (as a readonly
11
11
  * property of type `U`). `Omit<T, K>` first drops any existing `K`, so re-binding
@@ -14,7 +14,7 @@ type Prettify<T> = { [K in keyof T]: T[K] } & {};
14
14
  *
15
15
  * @internal
16
16
  */
17
- type Bound<T, K extends string, U> = Prettify<Omit<T, K> & { readonly [P in K]: U }>;
17
+ type Bound<T, K extends string, U> = Prettify<Omit<T, K> & { readonly [P in K]: U; }>;
18
18
  /**
19
19
  * Compile-time rejection of a thenable callback result — the type-level
20
20
  * enforcement of "combinator callbacks are synchronous" (see the
@@ -34,7 +34,7 @@ type Bound<T, K extends string, U> = Prettify<Omit<T, K> & { readonly [P in K]:
34
34
  type NotThenable<R> = [R] extends [PromiseLike<unknown>] ? "unthrown: combinator callbacks are synchronous — lift async work with fromPromise and compose with flatMap" : unknown;
35
35
  /**
36
36
  * The fluent method surface every {@link Result} variant carries — the
37
- * combinators (`map`, `flatMap`, `mapErr`, `match`, `unwrap`, …), documented one
37
+ * combinators (`map`, `flatMap`, `mapErr`, `match`, `get`, …), documented one
38
38
  * per entry below. Factored out so the three variants ({@link OkView},
39
39
  * {@link ErrView}, {@link DefectView}) can each intersect it; {@link AsyncResult}
40
40
  * mirrors this surface with async signatures.
@@ -79,6 +79,15 @@ type ResultMethods<T, E> = {
79
79
  * Runs only on `Ok`. If `f` throws, the throw becomes a `Defect`. An async
80
80
  * callback is rejected at compile time ({@link NotThenable}).
81
81
  *
82
+ * @remarks
83
+ * `f`'s return value is **ignored** — a `Result` returned by the effect
84
+ * compiles but is discarded, `Err` and all. If the effect can fail, sequence
85
+ * it instead of tapping it: a `Result`-returning effect goes in
86
+ * {@link ResultMethods.flatTap | flatTap}; an `AsyncResult`-returning effect
87
+ * cannot be sequenced from the sync surface — lift the chain with
88
+ * {@link ResultMethods.toAsync | toAsync} and use the async
89
+ * {@link AsyncResultMethods.flatTap | flatTap} (which accepts both).
90
+ *
82
91
  * @param f - the side effect (its return value is ignored).
83
92
  */
84
93
  tap<R>(f: (value: T) => R & NotThenable<R>): Result$1<T, E>;
@@ -143,6 +152,15 @@ type ResultMethods<T, E> = {
143
152
  * @typeParam U - the replacement value type.
144
153
  */
145
154
  as<U>(value: U): Result$1<U, E>;
155
+ /**
156
+ * Drop the success value, collapsing the success type to `void`.
157
+ *
158
+ * The named form of `map(() => undefined)`. Runs only on `Ok` (the value is
159
+ * replaced with `undefined`); `Err` and `Defect` pass through. Unlike
160
+ * `as(undefined)` — which produces `Result<undefined, E>` — the success type
161
+ * is `void`: the value's story ends here.
162
+ */
163
+ discard(): Result$1<void, E>;
146
164
  /**
147
165
  * Transform the modeled error with `f`.
148
166
  *
@@ -155,7 +173,8 @@ type ResultMethods<T, E> = {
155
173
  */
156
174
  mapErr<E2>(f: (error: E) => E2 & NotThenable<E2>): Result$1<T, E2>;
157
175
  /**
158
- * Recover from an `Err` by producing another `Result`.
176
+ * Sequence from an `Err` by producing another `Result` — the error-channel
177
+ * mirror of {@link ResultMethods.flatMap | flatMap}.
159
178
  *
160
179
  * Runs `f` only on `Err`; `Ok` and `Defect` pass through. If `f` throws, the
161
180
  * throw becomes a `Defect`.
@@ -164,10 +183,22 @@ type ResultMethods<T, E> = {
164
183
  * @typeParam E2 - the error type `f` may produce instead.
165
184
  * @param f - produces a fallback `Result` from the current error.
166
185
  */
186
+ flatMapErr<U, E2>(f: (error: E) => Result$1<U, E2>): Result$1<T | U, E2>;
187
+ /**
188
+ * Sequence from an `Err` by producing another `Result`.
189
+ *
190
+ * @deprecated Renamed to {@link ResultMethods.flatMapErr | flatMapErr} — it is
191
+ * `flatMap` on the error channel, so it now follows the `…Err` convention. This
192
+ * alias will be removed in a future major.
193
+ *
194
+ * @typeParam U - an alternative success type `f` may produce.
195
+ * @typeParam E2 - the error type `f` may produce instead.
196
+ * @param f - produces a fallback `Result` from the current error.
197
+ */
167
198
  orElse<U, E2>(f: (error: E) => Result$1<U, E2>): Result$1<T | U, E2>;
168
199
  /**
169
200
  * Recover from an `Err` by producing a success value, emptying the error
170
- * channel.
201
+ * channel. Pairs with {@link ResultMethods.recoverDefect | recoverDefect}.
171
202
  *
172
203
  * @remarks
173
204
  * The result type is `Result<T | U, never>`, but `never` describes only the
@@ -179,6 +210,17 @@ type ResultMethods<T, E> = {
179
210
  * @typeParam U - the recovered success type.
180
211
  * @param f - produces a success value from the current error.
181
212
  */
213
+ recoverErr<U>(f: (error: E) => U & NotThenable<U>): Result$1<T | U, never>;
214
+ /**
215
+ * Recover from an `Err` by producing a success value.
216
+ *
217
+ * @deprecated Renamed to {@link ResultMethods.recoverErr | recoverErr} — it now
218
+ * pairs with {@link ResultMethods.recoverDefect | recoverDefect} and follows the
219
+ * `…Err` convention. This alias will be removed in a future major.
220
+ *
221
+ * @typeParam U - the recovered success type.
222
+ * @param f - produces a success value from the current error.
223
+ */
182
224
  recover<U>(f: (error: E) => U & NotThenable<U>): Result$1<T | U, never>;
183
225
  /**
184
226
  * Run a side effect on the error and pass the `Result` through unchanged.
@@ -188,6 +230,14 @@ type ResultMethods<T, E> = {
188
230
  * never destroys it. An async callback is rejected at compile time
189
231
  * ({@link NotThenable}).
190
232
  *
233
+ * @remarks
234
+ * As with {@link ResultMethods.tap | tap}, `f`'s return value is ignored — a
235
+ * failable `Result`-returning effect belongs in
236
+ * {@link ResultMethods.flatTapErr | flatTapErr}; an `AsyncResult`-returning
237
+ * one needs the chain lifted with {@link ResultMethods.toAsync | toAsync}
238
+ * first (the async {@link AsyncResultMethods.flatTapErr | flatTapErr}
239
+ * accepts both).
240
+ *
191
241
  * @param f - the side effect (its return value is ignored).
192
242
  */
193
243
  tapErr<R>(f: (error: E) => R & NotThenable<R>): Result$1<T, E>;
@@ -256,14 +306,23 @@ type ResultMethods<T, E> = {
256
306
  *
257
307
  * @remarks
258
308
  * Compiles only when the error channel is empty (`E = never`) — eliminate
259
- * modeled errors first (`match` / `recover` / `orElse`), or reach for the
260
- * `unwrapOr` / `unwrapOrElse` / `getOrNull` / `getOrUndefined` family (which
309
+ * modeled errors first (`match` / `recoverErr` / `flatMapErr`), or reach for the
310
+ * `getOr` / `getOrElse` / `getOrNull` / `getOrUndefined` family (which
261
311
  * recover an `Err`). If you get a `'this' context` type error here, that is
262
312
  * the gate: the receiver still has a non-`never` error channel.
263
313
  *
264
314
  * `E = never` empties only the **modeled** error channel — a `Defect` can
265
- * still be present, and `unwrap()` **rethrows its original cause** (it
266
- * _panics_); `Result<T, never>` does not mean `unwrap()` cannot throw.
315
+ * still be present, and `get()` **rethrows its original cause** (it
316
+ * _panics_); `Result<T, never>` does not mean `get()` cannot throw.
317
+ *
318
+ * @returns the `Ok` value.
319
+ */
320
+ get(this: Result$1<T, never>): T;
321
+ /**
322
+ * Extract the success value.
323
+ *
324
+ * @deprecated Renamed to {@link ResultMethods.get | get}, unifying the extractor
325
+ * family under `get…`. This alias will be removed in a future major.
267
326
  *
268
327
  * @returns the `Ok` value.
269
328
  */
@@ -277,7 +336,16 @@ type ResultMethods<T, E> = {
277
336
  * `Result` you hold usually still has a success type), so to inspect an
278
337
  * error prefer an `isErr()` guard or, in tests, `@unthrown/vitest`'s
279
338
  * `toBeErrWith`. A `Defect` still **rethrows its original cause** (a defect is
280
- * a bug, not an absent value), so this does not mean `unwrapErr()` can't throw.
339
+ * a bug, not an absent value), so this does not mean `getErr()` can't throw.
340
+ *
341
+ * @returns the `Err` value.
342
+ */
343
+ getErr(this: Result$1<never, E>): E;
344
+ /**
345
+ * Extract the modeled error.
346
+ *
347
+ * @deprecated Renamed to {@link ResultMethods.getErr | getErr}, unifying the
348
+ * extractor family under `get…`. This alias will be removed in a future major.
281
349
  *
282
350
  * @returns the `Err` value.
283
351
  */
@@ -290,6 +358,17 @@ type ResultMethods<T, E> = {
290
358
  * @throws Re-throws on a `Defect` — a Defect is a bug, not an absent value, so
291
359
  * it is never silently replaced.
292
360
  */
361
+ getOr<U>(fallback: U): T | U;
362
+ /**
363
+ * The success value, or `fallback` on `Err`.
364
+ *
365
+ * @deprecated Renamed to {@link ResultMethods.getOr | getOr}, unifying the
366
+ * extractor family under `get…`. This alias will be removed in a future major.
367
+ *
368
+ * @typeParam U - the fallback type (may differ from `T`; the return widens to `T | U`).
369
+ * @param fallback - returned when the result is an `Err`.
370
+ * @throws Re-throws on a `Defect`.
371
+ */
293
372
  unwrapOr<U>(fallback: U): T | U;
294
373
  /**
295
374
  * The success value, or `f(error)` on `Err`.
@@ -298,6 +377,17 @@ type ResultMethods<T, E> = {
298
377
  * @param f - lazily computes the fallback from the error (may return a different type; the return widens to `T | U`).
299
378
  * @throws Re-throws on a `Defect`.
300
379
  */
380
+ getOrElse<U>(f: (error: E) => U): T | U;
381
+ /**
382
+ * The success value, or `f(error)` on `Err`.
383
+ *
384
+ * @deprecated Renamed to {@link ResultMethods.getOrElse | getOrElse}, unifying
385
+ * the extractor family under `get…`. This alias will be removed in a future major.
386
+ *
387
+ * @typeParam U - the fallback type (may differ from `T`; the return widens to `T | U`).
388
+ * @param f - lazily computes the fallback from the error.
389
+ * @throws Re-throws on a `Defect`.
390
+ */
301
391
  unwrapOrElse<U>(f: (error: E) => U): T | U;
302
392
  /**
303
393
  * The success value, or `null` on `Err`.
@@ -310,10 +400,32 @@ type ResultMethods<T, E> = {
310
400
  *
311
401
  * @throws Re-throws on a `Defect`.
312
402
  */
313
- getOrUndefined(): T | undefined; /** Whether this result is `Ok` — narrows `this` to its {@link OkView} on `true`. */
314
- isOk(): this is OkView<T, E>; /** Whether this result is `Err` — narrows `this` to its {@link ErrView} on `true`. */
315
- isErr(): this is ErrView<E, T>; /** Whether this result is a `Defect` — narrows `this` to its {@link DefectView} on `true`. */
316
- isDefect(): this is DefectView<T, E>; /** Lift this synchronous `Result` into an {@link AsyncResult}. */
403
+ getOrUndefined(): T | undefined;
404
+ /**
405
+ * The success value, or **throw** the modeled error on `Err`.
406
+ *
407
+ * @remarks
408
+ * A deliberate escape hatch off the errors-as-values model. Unlike
409
+ * {@link ResultMethods.get | get} (type-gated to an empty error
410
+ * channel), this compiles on any `Result<T, E>` and **throws the `Err` value
411
+ * as-is** at the call site. Its purpose is to move a literal `throw` behind a
412
+ * method, so a `no-throw` lint rule can ban raw throws while this one
413
+ * sanctioned extraction remains — _not_ to replace principled handling. When
414
+ * you can keep the error a value, prefer {@link ResultMethods.match | match} /
415
+ * {@link ResultMethods.recoverErr | recoverErr} / {@link ResultMethods.flatMapErr | flatMapErr}.
416
+ *
417
+ * @returns the `Ok` value.
418
+ * @throws the modeled `error` on `Err`; re-throws the original `cause` on a
419
+ * `Defect` (a panic, like the rest of the `getOr…` family).
420
+ */
421
+ getOrThrow(): T;
422
+ /** Whether this result is `Ok` — narrows `this` to its {@link OkView} on `true`. */
423
+ isOk(): this is OkView<T, E>;
424
+ /** Whether this result is `Err` — narrows `this` to its {@link ErrView} on `true`. */
425
+ isErr(): this is ErrView<E, T>;
426
+ /** Whether this result is a `Defect` — narrows `this` to its {@link DefectView} on `true`. */
427
+ isDefect(): this is DefectView<T, E>;
428
+ /** Lift this synchronous `Result` into an {@link AsyncResult}. */
317
429
  toAsync(): AsyncResult$1<T, E>;
318
430
  };
319
431
  /**
@@ -433,7 +545,7 @@ type Awaitable<T> = {
433
545
  };
434
546
  /**
435
547
  * The async method surface every {@link AsyncResult} carries — the combinators
436
- * (`map`, `flatMap`, `mapErr`, `match`, `unwrap`, …) with their asynchronous
548
+ * (`map`, `flatMap`, `mapErr`, `match`, `get`, …) with their asynchronous
437
549
  * signatures, documented one per entry below. The async mirror of
438
550
  * {@link ResultMethods}: each entry links its synchronous counterpart and states
439
551
  * only the async delta.
@@ -467,7 +579,12 @@ type AsyncResultMethods<T, E> = {
467
579
  /**
468
580
  * Asynchronous {@link ResultMethods.tap | tap}. `f` is synchronous; a throw
469
581
  * becomes a `Defect`. An async callback is rejected at compile time
470
- * ({@link NotThenable}).
582
+ * ({@link NotThenable}) — and so is a returned `AsyncResult` (it is
583
+ * awaitable). Beware the near-miss: _calling_ an `AsyncResult`-returning
584
+ * effect inside the callback without returning it compiles and leaves the
585
+ * effect floating — fire-and-forget, never awaited, its `Err`/`Defect`
586
+ * unobserved. If the effect returns a `Result`/`AsyncResult`, use
587
+ * {@link AsyncResultMethods.flatTap | flatTap}.
471
588
  */
472
589
  tap<R>(f: (value: T) => R & NotThenable<R>): AsyncResult$1<T, E>;
473
590
  /**
@@ -488,8 +605,11 @@ type AsyncResultMethods<T, E> = {
488
605
  * plain value, bound under `name`. An async callback is rejected at compile
489
606
  * time ({@link NotThenable}).
490
607
  */
491
- let<K extends string, U>(name: K, f: (scope: T) => U & NotThenable<U>): AsyncResult$1<Bound<T, K, U>, E>; /** Asynchronous {@link ResultMethods.as | as}: replaces the value with `value`. */
608
+ let<K extends string, U>(name: K, f: (scope: T) => U & NotThenable<U>): AsyncResult$1<Bound<T, K, U>, E>;
609
+ /** Asynchronous {@link ResultMethods.as | as}: replaces the value with `value`. */
492
610
  as<U>(value: U): AsyncResult$1<U, E>;
611
+ /** Asynchronous {@link ResultMethods.discard | discard}: drops the value, collapsing the success type to `void`. */
612
+ discard(): AsyncResult$1<void, E>;
493
613
  /**
494
614
  * Asynchronous {@link ResultMethods.mapErr | mapErr}. `f` is synchronous; a
495
615
  * throw becomes a `Defect`. An async callback is rejected at compile time
@@ -497,21 +617,34 @@ type AsyncResultMethods<T, E> = {
497
617
  */
498
618
  mapErr<E2>(f: (error: E) => E2 & NotThenable<E2>): AsyncResult$1<T, E2>;
499
619
  /**
500
- * Asynchronous {@link ResultMethods.orElse | orElse}. `f` may return a `Result`
501
- * or an `AsyncResult`.
620
+ * Asynchronous {@link ResultMethods.flatMapErr | flatMapErr}. `f` may return a
621
+ * `Result` or an `AsyncResult`.
622
+ */
623
+ flatMapErr<U, E2>(f: (error: E) => Result$1<U, E2> | AsyncResult$1<U, E2>): AsyncResult$1<T | U, E2>;
624
+ /**
625
+ * @deprecated Renamed to {@link AsyncResultMethods.flatMapErr | flatMapErr}.
626
+ * This alias will be removed in a future major.
502
627
  */
503
628
  orElse<U, E2>(f: (error: E) => Result$1<U, E2> | AsyncResult$1<U, E2>): AsyncResult$1<T | U, E2>;
504
629
  /**
505
- * Asynchronous {@link ResultMethods.recover | recover}. `f` is synchronous; a
506
- * throw becomes a `Defect`. An async callback is rejected at compile time
507
- * ({@link NotThenable}).
630
+ * Asynchronous {@link ResultMethods.recoverErr | recoverErr}. `f` is
631
+ * synchronous; a throw becomes a `Defect`. An async callback is rejected at
632
+ * compile time ({@link NotThenable}).
633
+ */
634
+ recoverErr<U>(f: (error: E) => U & NotThenable<U>): AsyncResult$1<T | U, never>;
635
+ /**
636
+ * @deprecated Renamed to {@link AsyncResultMethods.recoverErr | recoverErr}.
637
+ * This alias will be removed in a future major.
508
638
  */
509
639
  recover<U>(f: (error: E) => U & NotThenable<U>): AsyncResult$1<T | U, never>;
510
640
  /**
511
641
  * Asynchronous {@link ResultMethods.tapErr | tapErr}. `f` is synchronous; if it
512
642
  * throws, the result is a `Defect` whose cause is an `AggregateError` of
513
643
  * `[thrown, original failure]` — observing a failure never destroys it. An
514
- * async callback is rejected at compile time ({@link NotThenable}).
644
+ * async callback is rejected at compile time ({@link NotThenable}). The
645
+ * {@link AsyncResultMethods.tap | tap} fire-and-forget caveat applies here
646
+ * too — a failable effect belongs in
647
+ * {@link AsyncResultMethods.flatTapErr | flatTapErr}.
515
648
  */
516
649
  tapErr<R>(f: (error: E) => R & NotThenable<R>): AsyncResult$1<T, E>;
517
650
  /**
@@ -545,21 +678,51 @@ type AsyncResultMethods<T, E> = {
545
678
  defect: (cause: unknown) => R;
546
679
  }): Promise<R>;
547
680
  /**
548
- * Asynchronous {@link ResultMethods.unwrap | unwrap}. Compiles only when the
681
+ * Asynchronous {@link ResultMethods.get | get}. Compiles only when the
549
682
  * error channel is empty (`this: AsyncResult<T, never>`); the returned promise
550
683
  * rejects on a `Defect` (rethrowing its cause).
551
684
  */
685
+ get(this: AsyncResult$1<T, never>): Promise<T>;
686
+ /**
687
+ * @deprecated Renamed to {@link AsyncResultMethods.get | get}. This alias will
688
+ * be removed in a future major.
689
+ */
552
690
  unwrap(this: AsyncResult$1<T, never>): Promise<T>;
553
691
  /**
554
- * Asynchronous {@link ResultMethods.unwrapErr | unwrapErr}. Compiles only when
692
+ * Asynchronous {@link ResultMethods.getErr | getErr}. Compiles only when
555
693
  * the success channel is empty (`this: AsyncResult<never, E>`); the returned
556
694
  * promise rejects on a `Defect` (rethrowing its cause).
557
695
  */
558
- unwrapErr(this: AsyncResult$1<never, E>): Promise<E>; /** Asynchronous {@link ResultMethods.unwrapOr | unwrapOr}. */
559
- unwrapOr<U>(fallback: U): Promise<T | U>; /** Asynchronous {@link ResultMethods.unwrapOrElse | unwrapOrElse}. */
560
- unwrapOrElse<U>(f: (error: E) => U): Promise<T | U>; /** Asynchronous {@link ResultMethods.getOrNull | getOrNull}. */
561
- getOrNull(): Promise<T | null>; /** Asynchronous {@link ResultMethods.getOrUndefined | getOrUndefined}. */
696
+ getErr(this: AsyncResult$1<never, E>): Promise<E>;
697
+ /**
698
+ * @deprecated Renamed to {@link AsyncResultMethods.getErr | getErr}. This alias
699
+ * will be removed in a future major.
700
+ */
701
+ unwrapErr(this: AsyncResult$1<never, E>): Promise<E>;
702
+ /** Asynchronous {@link ResultMethods.getOr | getOr}. */
703
+ getOr<U>(fallback: U): Promise<T | U>;
704
+ /**
705
+ * @deprecated Renamed to {@link AsyncResultMethods.getOr | getOr}. This alias
706
+ * will be removed in a future major.
707
+ */
708
+ unwrapOr<U>(fallback: U): Promise<T | U>;
709
+ /** Asynchronous {@link ResultMethods.getOrElse | getOrElse}. */
710
+ getOrElse<U>(f: (error: E) => U): Promise<T | U>;
711
+ /**
712
+ * @deprecated Renamed to {@link AsyncResultMethods.getOrElse | getOrElse}. This
713
+ * alias will be removed in a future major.
714
+ */
715
+ unwrapOrElse<U>(f: (error: E) => U): Promise<T | U>;
716
+ /** Asynchronous {@link ResultMethods.getOrNull | getOrNull}. */
717
+ getOrNull(): Promise<T | null>;
718
+ /** Asynchronous {@link ResultMethods.getOrUndefined | getOrUndefined}. */
562
719
  getOrUndefined(): Promise<T | undefined>;
720
+ /**
721
+ * Asynchronous {@link ResultMethods.getOrThrow | getOrThrow} — the returned
722
+ * promise **rejects** with the modeled error on `Err` (or the original cause
723
+ * on a `Defect`), rather than throwing synchronously.
724
+ */
725
+ getOrThrow(): Promise<T>;
563
726
  };
564
727
  /**
565
728
  * The asynchronous counterpart of {@link Result}: an awaitable wrapper carrying
@@ -572,8 +735,8 @@ type AsyncResultMethods<T, E> = {
572
735
  * rejection would silently become a `Defect`, skipping the triage that
573
736
  * {@link fromPromise} forces. To do further async work, re-enter through a
574
737
  * qualified boundary and compose it: `ar.flatMap((v) => fromPromise(work(v),
575
- * qualify))`. The eliminators (`unwrap`, …) return promises; the binds
576
- * (`flatMap`, `flatTap`, `orElse`, `recoverDefect`) additionally accept an
738
+ * qualify))`. The eliminators (`get`, …) return promises; the binds
739
+ * (`flatMap`, `flatTap`, `flatMapErr`, `recoverDefect`) additionally accept an
577
740
  * `AsyncResult`. Its combinators are documented one per entry on
578
741
  * {@link AsyncResultMethods}.
579
742
  *
@@ -649,6 +812,21 @@ type AsyncOkOf<R> = R extends AsyncResult$1<infer T, unknown> ? T : never;
649
812
  type AsyncErrOf<R> = R extends AsyncResult$1<unknown, infer E> ? E : never;
650
813
  //#endregion
651
814
  //#region src/constructors.d.ts
815
+ /**
816
+ * Construct a successful `void` {@link Result} — `Result<void, never>` —
817
+ * sparing you `Ok(undefined)` and typing the success channel `void`, not
818
+ * `undefined`.
819
+ *
820
+ * @example
821
+ * ```ts
822
+ * import { Ok } from "unthrown";
823
+ *
824
+ * Ok(); // => a void success: Result<void, never>
825
+ * ```
826
+ *
827
+ * @category Constructors
828
+ */
829
+ declare function Ok(): Result$1<void, never>;
652
830
  /**
653
831
  * Construct a successful {@link Result}.
654
832
  *
@@ -660,7 +838,7 @@ type AsyncErrOf<R> = R extends AsyncResult$1<unknown, infer E> ? E : never;
660
838
  * import { Ok } from "unthrown";
661
839
  *
662
840
  * Ok(2).map((n) => n + 1); // => Ok(3)
663
- * Ok(42).unwrap(); // => 42
841
+ * Ok(42).get(); // => 42
664
842
  * ```
665
843
  *
666
844
  * @category Constructors
@@ -677,12 +855,75 @@ declare function Ok<T>(value: T): Result$1<T, never>;
677
855
  * import { Err } from "unthrown";
678
856
  *
679
857
  * Err("not_found").map((n) => n + 1); // => Err("not_found") (map skipped)
680
- * Err("not_found").unwrapErr(); // => "not_found"
858
+ * Err("not_found").getErr(); // => "not_found"
681
859
  * ```
682
860
  *
683
861
  * @category Constructors
684
862
  */
685
863
  declare function Err<E>(error: E): Result$1<never, E>;
864
+ /**
865
+ * Construct a successful `void` {@link AsyncResult} — `AsyncResult<void, never>`
866
+ * — the pre-lifted form of the no-arg {@link Ok}, sparing you
867
+ * `Ok(undefined).toAsync()`.
868
+ *
869
+ * @example
870
+ * ```ts
871
+ * import { OkAsync } from "unthrown";
872
+ *
873
+ * OkAsync(); // => a void success: AsyncResult<void, never>
874
+ * ```
875
+ *
876
+ * @category Constructors
877
+ */
878
+ declare function OkAsync(): AsyncResult$1<void, never>;
879
+ /**
880
+ * Construct a successful {@link AsyncResult} from a pure value — the pre-lifted
881
+ * form of {@link Ok}, sparing you `Ok(value).toAsync()`.
882
+ *
883
+ * @remarks
884
+ * Reach for this on the synchronous/early branch of an `AsyncResult`-returning
885
+ * function, so both branches share one return type without a trailing
886
+ * `.toAsync()`. Named with the `Async` suffix the async free functions carry
887
+ * (`allAsync`, `allFromDictAsync`); the {@link AsyncResult} companion aliases it
888
+ * as `AsyncResult.Ok` (the namespace already says "async", so the suffix drops).
889
+ *
890
+ * @typeParam T - the success value type.
891
+ * @param value - the success value to wrap.
892
+ *
893
+ * @example
894
+ * ```ts
895
+ * import { OkAsync, type AsyncResult } from "unthrown";
896
+ *
897
+ * function loadItems(ids: string[]): AsyncResult<Item[], never> {
898
+ * if (ids.length === 0) return OkAsync([]); // no more Ok([]).toAsync()
899
+ * return itemRepository.load(ids);
900
+ * }
901
+ * ```
902
+ *
903
+ * @category Constructors
904
+ */
905
+ declare function OkAsync<T>(value: T): AsyncResult$1<T, never>;
906
+ /**
907
+ * Construct a failed {@link AsyncResult} carrying a **modeled** error — the
908
+ * pre-lifted form of {@link Err}, sparing you `Err(error).toAsync()`.
909
+ *
910
+ * @remarks
911
+ * The error-channel mirror of {@link OkAsync}; see it for the naming and the
912
+ * `AsyncResult.Err` companion alias.
913
+ *
914
+ * @typeParam E - the modeled error type.
915
+ * @param error - the domain error to wrap.
916
+ *
917
+ * @example
918
+ * ```ts
919
+ * import { ErrAsync } from "unthrown";
920
+ *
921
+ * ErrAsync("not_found"); // AsyncResult<never, string>
922
+ * ```
923
+ *
924
+ * @category Constructors
925
+ */
926
+ declare function ErrAsync<E>(error: E): AsyncResult$1<never, E>;
686
927
  /**
687
928
  * Type guard: narrow a {@link Result} to its `Ok` variant, exposing `.value`.
688
929
  *
@@ -750,8 +991,8 @@ declare function isDefect<T, E>(r: Result$1<T, E>): r is DefectView<T, E>;
750
991
  //#endregion
751
992
  //#region src/core.d.ts
752
993
  /**
753
- * Thrown by a {@link Result}'s `unwrap` / `unwrapErr` when the assertion is
754
- * wrong on a *modeled* result — `unwrap()` on an `Err`, or `unwrapErr()` on an
994
+ * Thrown by a {@link Result}'s `get` / `getErr` when the assertion is
995
+ * wrong on a *modeled* result — `get()` on an `Err`, or `getErr()` on an
755
996
  * `Ok`.
756
997
  *
757
998
  * @remarks
@@ -763,7 +1004,7 @@ declare function isDefect<T, E>(r: Result$1<T, E>): r is DefectView<T, E>;
763
1004
  * A `Defect` is never wrapped in an `UnwrapError`: its original cause is
764
1005
  * re-thrown (with its original stack) instead.
765
1006
  *
766
- * `unwrap()` and `unwrapErr()` are type-gated (`this: Result<T, never>` /
1007
+ * `get()` and `getErr()` are type-gated (`this: Result<T, never>` /
767
1008
  * `Result<never, E>`), so the wrong-variant branch that throws this is
768
1009
  * unreachable through well-typed code — it remains only as a defensive guard
769
1010
  * against unsound runtime misuse (e.g. an `as` cast past the gate).
@@ -774,8 +1015,8 @@ declare function isDefect<T, E>(r: Result$1<T, E>): r is DefectView<T, E>;
774
1015
  */
775
1016
  declare class UnwrapError<E = unknown> extends Error {
776
1017
  /**
777
- * The offending value: the `Err` error for `unwrap()`, or the `Ok` value for
778
- * `unwrapErr()`.
1018
+ * The offending value: the `Err` error for `get()`, or the `Ok` value for
1019
+ * `getErr()`.
779
1020
  */
780
1021
  readonly error: E;
781
1022
  constructor(error: E);
@@ -893,9 +1134,9 @@ type Defect = {
893
1134
  * import { fromNullable } from "unthrown";
894
1135
  *
895
1136
  * const map = new Map([["a", 1]]);
896
- * fromNullable(map.get("a"), () => "absent").unwrapOr(0); // => 1
1137
+ * fromNullable(map.get("a"), () => "absent").getOr(0); // => 1
897
1138
  * fromNullable(map.get("z"), () => "absent"); // => Err("absent")
898
- * fromNullable(0, () => "absent").unwrapOr(-1); // => 0 (falsy but present)
1139
+ * fromNullable(0, () => "absent").getOr(-1); // => 0 (falsy but present)
899
1140
  * ```
900
1141
  */
901
1142
  declare function fromNullable<T, E>(value: T | null | undefined, onAbsent: () => E): Result$1<NonNullable<T>, E>;
@@ -913,7 +1154,7 @@ declare function fromNullable<T, E>(value: T | null | undefined, onAbsent: () =>
913
1154
  * `qualify`'s return is **subtracted** from `E`, never inferred into it. So a
914
1155
  * `qualify` that returns *only* `defect(cause)` yields `E = never` (a Defect is
915
1156
  * out-of-band and must not pollute the error channel); reach for
916
- * {@link fromSafePromise} when every failure is a Defect.
1157
+ * {@link fromSafeThrowable} when every throw is a Defect.
917
1158
  *
918
1159
  * @typeParam A - the wrapped function's argument tuple.
919
1160
  * @typeParam T - the wrapped function's return type.
@@ -937,11 +1178,41 @@ declare function fromNullable<T, E>(value: T | null | undefined, onAbsent: () =>
937
1178
  * cause instanceof SyntaxError ? ("invalid_json" as const) : defect(cause),
938
1179
  * );
939
1180
  *
940
- * parse('{"ok":true}').unwrapOr(null); // => { ok: true }
1181
+ * parse('{"ok":true}').getOr(null); // => { ok: true }
941
1182
  * parse("nope"); // => Err("invalid_json")
942
1183
  * ```
943
1184
  */
944
1185
  declare function fromThrowable<A extends unknown[], T, R>(fn: (...args: A) => T, qualify: (cause: unknown, defect: (cause: unknown) => Defect) => R): (...args: A) => Result$1<T, Exclude<R, Defect>>;
1186
+ /**
1187
+ * Wrap a throwing synchronous function asserted **not** to fail in any modeled
1188
+ * way: any throw becomes a `Defect`.
1189
+ *
1190
+ * @remarks
1191
+ * The synchronous counterpart of {@link fromSafePromise}. Use it only when a
1192
+ * throw genuinely indicates a bug rather than an anticipated outcome — the
1193
+ * error channel is `never`, so there is nothing to triage; there is no
1194
+ * `qualify`. When some throws *are* anticipated, reach for
1195
+ * {@link fromThrowable} and triage them.
1196
+ *
1197
+ * @typeParam A - the wrapped function's argument tuple.
1198
+ * @typeParam T - the wrapped function's return type.
1199
+ * @param fn - the throwing function to wrap.
1200
+ * @returns a function with the same arguments returning `Result<T, never>`.
1201
+ *
1202
+ * @category Interop
1203
+ *
1204
+ * @example
1205
+ * ```ts
1206
+ * import { fromSafeThrowable } from "unthrown";
1207
+ *
1208
+ * // A decode failure here is a bug (the row came from our own schema), so
1209
+ * // every throw is a defect — no throwaway `(cause, defect) => defect(cause)`.
1210
+ * const decode = fromSafeThrowable((row: Row) => userSchema.parse(row));
1211
+ *
1212
+ * decode(row); // => Result<User, never> — a throw becomes a Defect
1213
+ * ```
1214
+ */
1215
+ declare function fromSafeThrowable<A extends unknown[], T>(fn: (...args: A) => T): (...args: A) => Result$1<T, never>;
945
1216
  /**
946
1217
  * Wrap a `Promise` (or a thunk producing one) as an {@link AsyncResult}, forcing
947
1218
  * every rejection to be triaged.
@@ -987,7 +1258,8 @@ declare function fromPromise<T, R>(promise: Promise<T> | (() => Promise<T>), qua
987
1258
  * @remarks
988
1259
  * Use this only when a rejection genuinely indicates a bug rather than an
989
1260
  * anticipated outcome — the error channel is `never`, so there is nothing to
990
- * triage. (`await`-ing still yields a `Result`; it never throws.)
1261
+ * triage. (`await`-ing still yields a `Result`; it never throws.) The
1262
+ * synchronous counterpart is {@link fromSafeThrowable}.
991
1263
  *
992
1264
  * @typeParam T - the resolved value type.
993
1265
  * @param promise - the promise, or a thunk returning one.
@@ -998,7 +1270,7 @@ declare function fromPromise<T, R>(promise: Promise<T> | (() => Promise<T>), qua
998
1270
  * ```ts
999
1271
  * import { fromSafePromise } from "unthrown";
1000
1272
  *
1001
- * (await fromSafePromise(Promise.resolve(3))).unwrap(); // => 3
1273
+ * (await fromSafePromise(Promise.resolve(3))).get(); // => 3
1002
1274
  * // a rejection becomes a Defect (never a modeled Err):
1003
1275
  * await fromSafePromise(Promise.reject(new Error("boom"))); // => Defect(Error("boom"))
1004
1276
  * ```
@@ -1044,11 +1316,11 @@ type AsyncResultRecord = Record<string, AsyncResult$1<unknown, unknown>>;
1044
1316
  * ```ts
1045
1317
  * import { all, Ok, Err } from "unthrown";
1046
1318
  *
1047
- * all([Ok(1), Ok("a"), Ok(true)]).unwrap(); // => [1, "a", true] (typed [number, string, boolean])
1319
+ * all([Ok(1), Ok("a"), Ok(true)]).get(); // => [1, "a", true] (typed [number, string, boolean])
1048
1320
  * all([Ok(1), Err("e"), Ok(3)]); // => Err("e") (short-circuits on the first Err)
1049
1321
  * ```
1050
1322
  */
1051
- declare function all<Rs extends readonly Result$1<unknown, unknown>[]>(results: readonly [...Rs]): Result$1<AllOk<Rs, { [K in keyof Rs]: OkOf<Rs[K]> }>, ErrOf<Rs[number]>>;
1323
+ declare function all<Rs extends readonly Result$1<unknown, unknown>[]>(results: readonly [...Rs]): Result$1<AllOk<Rs, { [K in keyof Rs]: OkOf<Rs[K]>; }>, ErrOf<Rs[number]>>;
1052
1324
  /**
1053
1325
  * Collect a **record** of {@link Result}s into a single `Result` of a record of
1054
1326
  * their success values — `allFromDict({ a: Result<A, E>, b: Result<B, E> })` is
@@ -1065,11 +1337,11 @@ declare function all<Rs extends readonly Result$1<unknown, unknown>[]>(results:
1065
1337
  * ```ts
1066
1338
  * import { allFromDict, Ok, Err } from "unthrown";
1067
1339
  *
1068
- * allFromDict({ id: Ok(1), name: Ok("ada") }).unwrap(); // => { id: 1, name: "ada" }
1340
+ * allFromDict({ id: Ok(1), name: Ok("ada") }).get(); // => { id: 1, name: "ada" }
1069
1341
  * allFromDict({ id: Ok(1), name: Err("missing") }); // => Err("missing")
1070
1342
  * ```
1071
1343
  */
1072
- declare function allFromDict<R extends ResultRecord>(results: R): Result$1<{ [K in keyof R]: OkOf<R[K]> }, ErrOf<R[keyof R]>>;
1344
+ declare function allFromDict<R extends ResultRecord>(results: R): Result$1<{ [K in keyof R]: OkOf<R[K]>; }, ErrOf<R[keyof R]>>;
1073
1345
  /**
1074
1346
  * The asynchronous counterpart of {@link all}: combine a tuple/array of
1075
1347
  * {@link AsyncResult}s into one `AsyncResult` of all their success values.
@@ -1087,10 +1359,10 @@ declare function allFromDict<R extends ResultRecord>(results: R): Result$1<{ [K
1087
1359
  * import { allAsync, fromSafePromise } from "unthrown";
1088
1360
  *
1089
1361
  * const both = allAsync([fromSafePromise(Promise.resolve(1)), fromSafePromise(Promise.resolve(2))]);
1090
- * (await both).unwrap(); // => [1, 2]
1362
+ * (await both).get(); // => [1, 2]
1091
1363
  * ```
1092
1364
  */
1093
- declare function allAsync<Rs extends readonly AsyncResult$1<unknown, unknown>[]>(results: readonly [...Rs]): AsyncResult$1<AllOk<Rs, { [K in keyof Rs]: AsyncOkOf<Rs[K]> }>, AsyncErrOf<Rs[number]>>;
1365
+ declare function allAsync<Rs extends readonly AsyncResult$1<unknown, unknown>[]>(results: readonly [...Rs]): AsyncResult$1<AllOk<Rs, { [K in keyof Rs]: AsyncOkOf<Rs[K]>; }>, AsyncErrOf<Rs[number]>>;
1094
1366
  /**
1095
1367
  * The asynchronous counterpart of {@link allFromDict}: combine a record of
1096
1368
  * {@link AsyncResult}s into one `AsyncResult` of a record of their values.
@@ -1109,18 +1381,19 @@ declare function allAsync<Rs extends readonly AsyncResult$1<unknown, unknown>[]>
1109
1381
  * a: fromSafePromise(Promise.resolve(1)),
1110
1382
  * b: fromSafePromise(Promise.resolve("x")),
1111
1383
  * });
1112
- * (await both).unwrap(); // => { a: 1, b: "x" }
1384
+ * (await both).get(); // => { a: 1, b: "x" }
1113
1385
  * ```
1114
1386
  */
1115
- declare function allFromDictAsync<R extends AsyncResultRecord>(results: R): AsyncResult$1<{ [K in keyof R]: AsyncOkOf<R[K]> }, AsyncErrOf<R[keyof R]>>;
1387
+ declare function allFromDictAsync<R extends AsyncResultRecord>(results: R): AsyncResult$1<{ [K in keyof R]: AsyncOkOf<R[K]>; }, AsyncErrOf<R[keyof R]>>;
1116
1388
  //#endregion
1117
1389
  //#region src/facade.d.ts
1118
1390
  /**
1119
1391
  * Companion object grouping the **`Result`-producing** entry points under a
1120
1392
  * single, discoverable namespace: {@link Result.Ok}, {@link Result.Err},
1121
1393
  * {@link Result.Do}, {@link Result.fromNullable}, {@link Result.fromThrowable},
1122
- * {@link Result.all}, {@link Result.allFromDict}, {@link Result.isOk},
1123
- * {@link Result.isErr}, {@link Result.isDefect}, {@link Result.isResult}.
1394
+ * {@link Result.fromSafeThrowable}, {@link Result.all},
1395
+ * {@link Result.allFromDict}, {@link Result.isOk}, {@link Result.isErr},
1396
+ * {@link Result.isDefect}, {@link Result.isResult}.
1124
1397
  *
1125
1398
  * @remarks
1126
1399
  * Purely additive sugar — each member **is** the corresponding free function.
@@ -1137,7 +1410,7 @@ declare function allFromDictAsync<R extends AsyncResultRecord>(results: R): Asyn
1137
1410
  * @example
1138
1411
  * ```ts
1139
1412
  * import { Result } from "unthrown";
1140
- * Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).unwrap(); // => 2
1413
+ * Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).get(); // => 2
1141
1414
  * ```
1142
1415
  */
1143
1416
  declare const Result: {
@@ -1146,6 +1419,7 @@ declare const Result: {
1146
1419
  readonly Do: typeof Do;
1147
1420
  readonly fromNullable: typeof fromNullable;
1148
1421
  readonly fromThrowable: typeof fromThrowable;
1422
+ readonly fromSafeThrowable: typeof fromSafeThrowable;
1149
1423
  readonly all: typeof all;
1150
1424
  readonly allFromDict: typeof allFromDict;
1151
1425
  readonly isOk: typeof isOk;
@@ -1160,7 +1434,7 @@ declare const Result: {
1160
1434
  *
1161
1435
  * @remarks
1162
1436
  * A `Result` is a discriminated union, so TypeDoc can't list its methods on this
1163
- * alias. Its fluent combinators (`map`, `flatMap`, `match`, `unwrap`, …) are
1437
+ * alias. Its fluent combinators (`map`, `flatMap`, `match`, `get`, …) are
1164
1438
  * documented one per entry on {@link ResultMethods} — the shared method surface
1165
1439
  * every variant carries. For "which one do I reach for?", see the
1166
1440
  * [Choosing a combinator](/guide/choosing-a-combinator) guide.
@@ -1170,18 +1444,20 @@ declare const Result: {
1170
1444
  type Result<T, E> = Result$1<T, E>;
1171
1445
  /**
1172
1446
  * Companion object grouping the **`AsyncResult`-producing** entry points under
1173
- * the matching namespace: {@link AsyncResult.fromPromise},
1174
- * {@link AsyncResult.fromSafePromise}, {@link AsyncResult.all},
1175
- * {@link AsyncResult.allFromDict}.
1447
+ * the matching namespace: {@link AsyncResult.Ok}, {@link AsyncResult.Err},
1448
+ * {@link AsyncResult.fromPromise}, {@link AsyncResult.fromSafePromise},
1449
+ * {@link AsyncResult.all}, {@link AsyncResult.allFromDict}.
1176
1450
  *
1177
1451
  * @remarks
1178
1452
  * The async sibling of {@link Result}. Statics are grouped by what they
1179
- * **return**, so `fromPromise`/`fromSafePromise` and the async aggregates sit
1180
- * here rather than on {@link Result}; the namespace already conveys "async", so
1181
- * the aggregates drop the `Async` suffix (`AsyncResult.all` is the free function
1182
- * `allAsync`; `AsyncResult.allFromDict` is `allFromDictAsync`). Like
1183
- * {@link Result}, the free functions remain the primary, tree-shakeable API; the
1184
- * value `AsyncResult` and the type {@link AsyncResult} share one name.
1453
+ * **return**, so the pre-lifted constructors, `fromPromise`/`fromSafePromise`,
1454
+ * and the async aggregates sit here rather than on {@link Result}; the namespace
1455
+ * already conveys "async", so the members drop the `Async` suffix their free
1456
+ * functions carry (`AsyncResult.Ok` is `OkAsync`; `AsyncResult.Err` is
1457
+ * `ErrAsync`; `AsyncResult.all` is `allAsync`; `AsyncResult.allFromDict` is
1458
+ * `allFromDictAsync`). Like {@link Result}, the free functions remain the
1459
+ * primary, tree-shakeable API; the value `AsyncResult` and the type
1460
+ * {@link AsyncResult} share one name.
1185
1461
  *
1186
1462
  * @category Facade
1187
1463
  *
@@ -1189,10 +1465,12 @@ type Result<T, E> = Result$1<T, E>;
1189
1465
  * ```ts
1190
1466
  * import { AsyncResult } from "unthrown";
1191
1467
  * const user = await AsyncResult.fromPromise(fetchUser(id), (c, defect) => defect(c));
1192
- * user.unwrap(); // => the fetched user (on success)
1468
+ * user.get(); // => the fetched user (on success)
1193
1469
  * ```
1194
1470
  */
1195
1471
  declare const AsyncResult: {
1472
+ readonly Ok: typeof OkAsync;
1473
+ readonly Err: typeof ErrAsync;
1196
1474
  readonly fromPromise: typeof fromPromise;
1197
1475
  readonly fromSafePromise: typeof fromSafePromise;
1198
1476
  readonly all: typeof allAsync;
@@ -1205,7 +1483,7 @@ declare const AsyncResult: {
1205
1483
  *
1206
1484
  * @remarks
1207
1485
  * `AsyncResult` carries the async fluent surface; its combinators (`map`,
1208
- * `flatMap`, `match`, `unwrap`, …) are documented one per entry — with their
1486
+ * `flatMap`, `match`, `get`, …) are documented one per entry — with their
1209
1487
  * async signatures — on {@link AsyncResultMethods}. For "which one do I reach
1210
1488
  * for?", see the [Choosing a combinator](/guide/choosing-a-combinator) guide.
1211
1489
  *
@@ -1325,7 +1603,7 @@ type TagHandlers<T, E extends {
1325
1603
  Defect: (cause: unknown) => R;
1326
1604
  } & { [K in E["_tag"]]: (error: Extract<E, {
1327
1605
  _tag: K;
1328
- }>) => R };
1606
+ }>) => R; };
1329
1607
  /**
1330
1608
  * The channel-handler names are reserved: an error tag named `"Ok"` or
1331
1609
  * `"Defect"` would collide with them inside {@link TagHandlers}, so
@@ -1381,5 +1659,5 @@ declare function matchTags<T, E extends {
1381
1659
  _tag: string;
1382
1660
  }, R>(result: AsyncResult$1<T, E>, handlers: TagHandlers<T, E, R> & ([Extract<E["_tag"], "Ok" | "Defect">] extends [never] ? unknown : ReservedTagError)): Promise<R>;
1383
1661
  //#endregion
1384
- export { type AsyncErrOf, type AsyncOkOf, AsyncResult, type AsyncResultMethods, type Awaitable, type DefectView, Do, Err, type ErrOf, type ErrView, type NotThenable, Ok, type OkOf, type OkView, Result, type ResultMethods, type TagHandlers, TaggedError, type TaggedErrorConstructor, type TaggedErrorInstance, UnwrapError, all, allAsync, allFromDict, allFromDictAsync, fromNullable, fromPromise, fromSafePromise, fromThrowable, isDefect, isErr, isOk, isResult, matchTags };
1662
+ export { type AsyncErrOf, type AsyncOkOf, AsyncResult, type AsyncResultMethods, type Awaitable, type DefectView, Do, Err, ErrAsync, type ErrOf, type ErrView, type NotThenable, Ok, OkAsync, type OkOf, type OkView, Result, type ResultMethods, type TagHandlers, TaggedError, type TaggedErrorConstructor, type TaggedErrorInstance, UnwrapError, all, allAsync, allFromDict, allFromDictAsync, fromNullable, fromPromise, fromSafePromise, fromSafeThrowable, fromThrowable, isDefect, isErr, isOk, isResult, matchTags };
1385
1663
  //# sourceMappingURL=index.d.mts.map