@sapphire/result 2.6.7-pr-725.55b1ff7b.0 → 2.7.0-next.0cb1b7f1
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/README.md +1 -2
- package/dist/cjs/index.cjs +1777 -540
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +297 -358
- package/dist/esm/index.d.mts +297 -358
- package/dist/esm/index.mjs +1772 -537
- package/dist/esm/index.mjs.map +1 -1
- package/dist/iife/index.global.js +1777 -540
- package/dist/iife/index.global.js.map +1 -1
- package/package.json +15 -14
package/dist/esm/index.d.mts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
type Awaitable<T> = PromiseLike<T> | T;
|
|
2
|
+
type If<Value extends boolean, TrueResult, FalseResult> = Value extends true ? TrueResult : Value extends false ? FalseResult : TrueResult | FalseResult;
|
|
2
3
|
|
|
4
|
+
declare const ValueProperty$1: unique symbol;
|
|
5
|
+
declare const SuccessProperty: unique symbol;
|
|
3
6
|
/**
|
|
4
7
|
* A type used to express computations that can fail, it can be used for returning and propagating errors. This is a
|
|
5
8
|
* type union with the variants `Ok(T)`, representing success and containing a value, and `Err(E)`, representing error
|
|
@@ -10,7 +13,15 @@ type Awaitable<T> = PromiseLike<T> | T;
|
|
|
10
13
|
*
|
|
11
14
|
* @see {@link https://doc.rust-lang.org/std/result/index.html}
|
|
12
15
|
*/
|
|
13
|
-
|
|
16
|
+
declare class Result<T, E, const Success extends boolean = boolean> {
|
|
17
|
+
/**
|
|
18
|
+
* Branded value to ensure `Success` is typed correctly.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
protected __STATUS__: Success;
|
|
22
|
+
private readonly [ValueProperty$1];
|
|
23
|
+
private readonly [SuccessProperty];
|
|
24
|
+
private constructor();
|
|
14
25
|
/**
|
|
15
26
|
* Returns `true` if the result is `Ok`.
|
|
16
27
|
*
|
|
@@ -27,7 +38,7 @@ interface IResult<T, E> {
|
|
|
27
38
|
*
|
|
28
39
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.is_ok}
|
|
29
40
|
*/
|
|
30
|
-
isOk(): this is
|
|
41
|
+
isOk(): this is Ok<T, E>;
|
|
31
42
|
/**
|
|
32
43
|
* Returns `true` if the result is `Ok` and the value inside of it matches a predicate.
|
|
33
44
|
*
|
|
@@ -49,7 +60,8 @@ interface IResult<T, E> {
|
|
|
49
60
|
*
|
|
50
61
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.is_ok_and}
|
|
51
62
|
*/
|
|
52
|
-
isOkAnd<R extends
|
|
63
|
+
isOkAnd<R extends T>(cb: (value: T) => value is R): this is Ok<R, E>;
|
|
64
|
+
isOkAnd<R extends boolean>(cb: (value: T) => R): this is Ok<T, E> & R;
|
|
53
65
|
/**
|
|
54
66
|
* Returns `true` if the result is `Err`.
|
|
55
67
|
*
|
|
@@ -66,7 +78,7 @@ interface IResult<T, E> {
|
|
|
66
78
|
*
|
|
67
79
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.is_err}
|
|
68
80
|
*/
|
|
69
|
-
isErr(): this is
|
|
81
|
+
isErr(): this is Err<E, T>;
|
|
70
82
|
/**
|
|
71
83
|
* Returns `true` if the result is `Err` and the value inside of it matches a predicate.
|
|
72
84
|
* @param cb The predicate.
|
|
@@ -89,7 +101,8 @@ interface IResult<T, E> {
|
|
|
89
101
|
*
|
|
90
102
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.is_err_and}
|
|
91
103
|
*/
|
|
92
|
-
isErrAnd<R extends
|
|
104
|
+
isErrAnd<R extends E>(cb: (error: E) => error is R): this is Err<R, T>;
|
|
105
|
+
isErrAnd<R extends boolean>(cb: (error: E) => R): this is Err<E, T> & R;
|
|
93
106
|
/**
|
|
94
107
|
* Converts from `Result<T, E>` to `Option<T>`.
|
|
95
108
|
*
|
|
@@ -108,7 +121,7 @@ interface IResult<T, E> {
|
|
|
108
121
|
*
|
|
109
122
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.ok}
|
|
110
123
|
*/
|
|
111
|
-
ok():
|
|
124
|
+
ok(): If<Success, Some<T>, None>;
|
|
112
125
|
/**
|
|
113
126
|
* Converts from `Result<T, E>` to `Option<E>`.
|
|
114
127
|
*
|
|
@@ -127,7 +140,7 @@ interface IResult<T, E> {
|
|
|
127
140
|
*
|
|
128
141
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.err}
|
|
129
142
|
*/
|
|
130
|
-
err():
|
|
143
|
+
err(): If<Success, None, Some<E>>;
|
|
131
144
|
/**
|
|
132
145
|
* Maps a `Result<T, E>` to `Result<U, E>` by applying a function to a contained `Ok` value, leaving an `Err` value
|
|
133
146
|
* untouched.
|
|
@@ -146,7 +159,7 @@ interface IResult<T, E> {
|
|
|
146
159
|
*
|
|
147
160
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.map}
|
|
148
161
|
*/
|
|
149
|
-
map<
|
|
162
|
+
map<OutputValue>(cb: (value: T) => OutputValue): If<Success, Ok<OutputValue, E>, Err<E>>;
|
|
150
163
|
/**
|
|
151
164
|
* Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a contained `Ok` value, leaving an `Err` value
|
|
152
165
|
* untouched.
|
|
@@ -176,7 +189,7 @@ interface IResult<T, E> {
|
|
|
176
189
|
*
|
|
177
190
|
* @note This is an extension not supported in Rust
|
|
178
191
|
*/
|
|
179
|
-
mapInto<
|
|
192
|
+
mapInto<OutputResult extends AnyResult>(cb: (value: T) => OutputResult): If<Success, OutputResult, Err<E>>;
|
|
180
193
|
/**
|
|
181
194
|
* Returns the provided default (if `Err`), or applies a function to the contained value (if `Ok`),
|
|
182
195
|
*
|
|
@@ -198,7 +211,7 @@ interface IResult<T, E> {
|
|
|
198
211
|
*
|
|
199
212
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.map_or}
|
|
200
213
|
*/
|
|
201
|
-
mapOr<
|
|
214
|
+
mapOr<MappedOutputValue, DefaultOutputValue>(defaultValue: DefaultOutputValue, cb: (value: T) => MappedOutputValue): If<Success, MappedOutputValue, DefaultOutputValue>;
|
|
202
215
|
/**
|
|
203
216
|
* Maps a `Result<T, E>` to `U` by applying fallback function default to a contained `Err` value, or function `cb`
|
|
204
217
|
* to a contained `Ok` value.
|
|
@@ -220,7 +233,7 @@ interface IResult<T, E> {
|
|
|
220
233
|
*
|
|
221
234
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.map_or_else}
|
|
222
235
|
*/
|
|
223
|
-
mapOrElse<
|
|
236
|
+
mapOrElse<OutputValue, OutputError>(op: (error: E) => OutputError, cb: (value: T) => OutputValue): If<Success, OutputValue, OutputError>;
|
|
224
237
|
/**
|
|
225
238
|
* Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a contained `Err` value, leaving an `Ok` value
|
|
226
239
|
* untouched.
|
|
@@ -241,7 +254,7 @@ interface IResult<T, E> {
|
|
|
241
254
|
*
|
|
242
255
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.map_err}
|
|
243
256
|
*/
|
|
244
|
-
mapErr<
|
|
257
|
+
mapErr<OutputError>(cb: (error: E) => OutputError): If<Success, Ok<T>, Err<OutputError>>;
|
|
245
258
|
/**
|
|
246
259
|
* Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a contained `Err` value, leaving an `Ok` value
|
|
247
260
|
* untouched.
|
|
@@ -270,7 +283,7 @@ interface IResult<T, E> {
|
|
|
270
283
|
*
|
|
271
284
|
* @note This is an extension not supported in Rust
|
|
272
285
|
*/
|
|
273
|
-
mapErrInto<
|
|
286
|
+
mapErrInto<OutputResult extends AnyResult>(cb: (error: E) => OutputResult): If<Success, Ok<T>, OutputResult>;
|
|
274
287
|
/**
|
|
275
288
|
* Calls the provided closure with a reference to the contained value (if `Ok`).
|
|
276
289
|
* @param cb The predicate.
|
|
@@ -289,7 +302,7 @@ interface IResult<T, E> {
|
|
|
289
302
|
*
|
|
290
303
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.inspect}
|
|
291
304
|
*/
|
|
292
|
-
inspect(cb: (value: T) =>
|
|
305
|
+
inspect(cb: (value: T) => unknown): this;
|
|
293
306
|
/**
|
|
294
307
|
* Calls the provided closure with a reference to the contained value (if `Ok`) and awaits it.
|
|
295
308
|
* @param cb The predicate.
|
|
@@ -308,7 +321,7 @@ interface IResult<T, E> {
|
|
|
308
321
|
*
|
|
309
322
|
* @note This is an extension not supported in Rust
|
|
310
323
|
*/
|
|
311
|
-
inspectAsync(cb: (value: T) => Awaitable<
|
|
324
|
+
inspectAsync(cb: (value: T) => Awaitable<unknown>): Promise<this>;
|
|
312
325
|
/**
|
|
313
326
|
* Calls the provided closure with a reference to the contained error (if `Err`).
|
|
314
327
|
* @param cb The predicate.
|
|
@@ -327,7 +340,7 @@ interface IResult<T, E> {
|
|
|
327
340
|
*
|
|
328
341
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.inspect_err}
|
|
329
342
|
*/
|
|
330
|
-
inspectErr(cb: (error: E) =>
|
|
343
|
+
inspectErr(cb: (error: E) => unknown): this;
|
|
331
344
|
/**
|
|
332
345
|
* Calls the provided closure with a reference to the contained error (if `Err`) and awaits it.
|
|
333
346
|
* @param cb The predicate.
|
|
@@ -346,7 +359,7 @@ interface IResult<T, E> {
|
|
|
346
359
|
*
|
|
347
360
|
* @note This is an extension not supported in Rust
|
|
348
361
|
*/
|
|
349
|
-
inspectErrAsync(cb: (error: E) => Awaitable<
|
|
362
|
+
inspectErrAsync(cb: (error: E) => Awaitable<unknown>): Promise<this>;
|
|
350
363
|
/**
|
|
351
364
|
* Returns an iterator over the possibly contained value.
|
|
352
365
|
*
|
|
@@ -395,7 +408,7 @@ interface IResult<T, E> {
|
|
|
395
408
|
*
|
|
396
409
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.expect}
|
|
397
410
|
*/
|
|
398
|
-
expect(message: string): T
|
|
411
|
+
expect(message: string): If<Success, T, never>;
|
|
399
412
|
/**
|
|
400
413
|
* Returns the contained `Err` value.
|
|
401
414
|
*
|
|
@@ -419,7 +432,7 @@ interface IResult<T, E> {
|
|
|
419
432
|
*
|
|
420
433
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.expect_err}
|
|
421
434
|
*/
|
|
422
|
-
expectErr(message: string): E
|
|
435
|
+
expectErr(message: string): If<Success, never, E>;
|
|
423
436
|
/**
|
|
424
437
|
* Returns the contained `Ok` value.
|
|
425
438
|
*
|
|
@@ -446,7 +459,7 @@ interface IResult<T, E> {
|
|
|
446
459
|
*
|
|
447
460
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap}
|
|
448
461
|
*/
|
|
449
|
-
unwrap(): T
|
|
462
|
+
unwrap(): If<Success, T, never>;
|
|
450
463
|
/**
|
|
451
464
|
* Returns the contained `Err` value.
|
|
452
465
|
*
|
|
@@ -473,7 +486,7 @@ interface IResult<T, E> {
|
|
|
473
486
|
*
|
|
474
487
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap_err}
|
|
475
488
|
*/
|
|
476
|
-
unwrapErr(): E
|
|
489
|
+
unwrapErr(): If<Success, never, E>;
|
|
477
490
|
/**
|
|
478
491
|
* Returns the contained `Ok` value or the provided default.
|
|
479
492
|
*
|
|
@@ -499,7 +512,7 @@ interface IResult<T, E> {
|
|
|
499
512
|
*
|
|
500
513
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap_or}
|
|
501
514
|
*/
|
|
502
|
-
unwrapOr<
|
|
515
|
+
unwrapOr<OutputValue>(defaultValue: OutputValue): If<Success, T, OutputValue>;
|
|
503
516
|
/**
|
|
504
517
|
* Returns the contained `Ok` value or computes it from a closure.
|
|
505
518
|
* @seealso {@link unwrap}
|
|
@@ -519,7 +532,7 @@ interface IResult<T, E> {
|
|
|
519
532
|
*
|
|
520
533
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap_or_else}
|
|
521
534
|
*/
|
|
522
|
-
unwrapOrElse<
|
|
535
|
+
unwrapOrElse<OutputValue>(op: (error: E) => OutputValue): If<Success, T, OutputValue>;
|
|
523
536
|
/**
|
|
524
537
|
* Returns the contained `Ok` value.
|
|
525
538
|
*
|
|
@@ -544,7 +557,7 @@ interface IResult<T, E> {
|
|
|
544
557
|
* });
|
|
545
558
|
* ```
|
|
546
559
|
*/
|
|
547
|
-
unwrapRaw(): T
|
|
560
|
+
unwrapRaw(): If<Success, T, never>;
|
|
548
561
|
/**
|
|
549
562
|
* Returns `result` if the result is `Ok`, otherwise returns the `Err` value of itself.
|
|
550
563
|
* @param result The result to check.
|
|
@@ -570,7 +583,7 @@ interface IResult<T, E> {
|
|
|
570
583
|
*
|
|
571
584
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.and}
|
|
572
585
|
*/
|
|
573
|
-
and<
|
|
586
|
+
and<OutputResult extends AnyResult>(result: OutputResult): If<Success, OutputResult, Err<E>>;
|
|
574
587
|
/**
|
|
575
588
|
* Calls `cb` if the result is `Ok`, otherwise returns the `Err` value of self.
|
|
576
589
|
*
|
|
@@ -590,7 +603,7 @@ interface IResult<T, E> {
|
|
|
590
603
|
*
|
|
591
604
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.and_then}
|
|
592
605
|
*/
|
|
593
|
-
andThen<
|
|
606
|
+
andThen<OutputResult extends AnyResult>(cb: (value: T) => OutputResult): If<Success, OutputResult, Err<E>>;
|
|
594
607
|
/**
|
|
595
608
|
* Return `result` if the result is `Err`, otherwise returns the `Ok` value of self.
|
|
596
609
|
*
|
|
@@ -625,7 +638,7 @@ interface IResult<T, E> {
|
|
|
625
638
|
*
|
|
626
639
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.or}
|
|
627
640
|
*/
|
|
628
|
-
or<
|
|
641
|
+
or<OutputResult extends AnyResult>(result: OutputResult): If<Success, Ok<T>, OutputResult>;
|
|
629
642
|
/**
|
|
630
643
|
* Calls `cb` if the result is `Err`, otherwise returns the `Ok` value of self.
|
|
631
644
|
*
|
|
@@ -645,7 +658,7 @@ interface IResult<T, E> {
|
|
|
645
658
|
*
|
|
646
659
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.or_else}
|
|
647
660
|
*/
|
|
648
|
-
orElse<
|
|
661
|
+
orElse<OutputResult extends AnyResult>(cb: (error: E) => OutputResult): If<Success, Ok<T>, OutputResult>;
|
|
649
662
|
/**
|
|
650
663
|
* Returns `true` if the result is an `Ok` and the given value strict equals it.
|
|
651
664
|
* @param value The value to compare.
|
|
@@ -668,7 +681,8 @@ interface IResult<T, E> {
|
|
|
668
681
|
*
|
|
669
682
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.contains}
|
|
670
683
|
*/
|
|
671
|
-
contains(value:
|
|
684
|
+
contains<const Value extends T>(this: Ok<T>, value: Value): this is Ok<Value>;
|
|
685
|
+
contains(this: Err<E>, value: T): false;
|
|
672
686
|
/**
|
|
673
687
|
* Returns `true` if the result is an `Err` and the given error strict equals it.
|
|
674
688
|
* @param error The error to compare.
|
|
@@ -691,7 +705,8 @@ interface IResult<T, E> {
|
|
|
691
705
|
*
|
|
692
706
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.contains_err}
|
|
693
707
|
*/
|
|
694
|
-
containsErr(error: E):
|
|
708
|
+
containsErr(this: Ok<T>, error: E): false;
|
|
709
|
+
containsErr<const Value extends E>(this: Err<E>, error: Value): this is Err<Value>;
|
|
695
710
|
/**
|
|
696
711
|
* Transposes a `Result` of an `Option` into an `Option` of a `Result`.
|
|
697
712
|
*
|
|
@@ -706,7 +721,7 @@ interface IResult<T, E> {
|
|
|
706
721
|
*
|
|
707
722
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.transpose}
|
|
708
723
|
*/
|
|
709
|
-
transpose<
|
|
724
|
+
transpose<InnerValue>(this: Result<Option<InnerValue>, E, Success>): If<Success, Option<Ok<InnerValue>>, Some<Err<E>>>;
|
|
710
725
|
/**
|
|
711
726
|
* Converts from `Result<Result<T, E>, E>` to `Result<T, E>`.
|
|
712
727
|
*
|
|
@@ -728,7 +743,7 @@ interface IResult<T, E> {
|
|
|
728
743
|
*
|
|
729
744
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.flatten}
|
|
730
745
|
*/
|
|
731
|
-
flatten<
|
|
746
|
+
flatten<InnerResult extends AnyResult>(this: Result<InnerResult, E, Success>): If<Success, InnerResult, Err<E>>;
|
|
732
747
|
/**
|
|
733
748
|
* Returns the `Ok` value if self is `Ok`, and the `Err` value if self is `Err`.
|
|
734
749
|
*
|
|
@@ -745,7 +760,7 @@ interface IResult<T, E> {
|
|
|
745
760
|
*
|
|
746
761
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.into_ok_or_err}
|
|
747
762
|
*/
|
|
748
|
-
intoOkOrErr(): T
|
|
763
|
+
intoOkOrErr(): If<Success, T, E>;
|
|
749
764
|
/**
|
|
750
765
|
* Returns a `Promise` object with the awaited value (if `Ok`) or the awaited error (if `Err`).
|
|
751
766
|
*
|
|
@@ -757,14 +772,14 @@ interface IResult<T, E> {
|
|
|
757
772
|
*
|
|
758
773
|
* @note This is an extension not supported in Rust
|
|
759
774
|
*/
|
|
760
|
-
intoPromise(): Promise<
|
|
775
|
+
intoPromise(): If<Success, Promise<Ok<Awaited<T>>>, Promise<Err<Awaited<E>>>>;
|
|
761
776
|
/**
|
|
762
777
|
* Checks whether or not `other` equals with self.
|
|
763
778
|
* @param other The other result to compare.
|
|
764
779
|
*
|
|
765
780
|
* @see {@link https://doc.rust-lang.org/std/cmp/trait.PartialEq.html#tymethod.eq}
|
|
766
781
|
*/
|
|
767
|
-
eq(other: Result<
|
|
782
|
+
eq<OtherValue extends T, OtherError extends E, OtherSuccess extends boolean>(other: Result<OtherValue, OtherError, OtherSuccess>): this is Result<OtherValue, OtherError, OtherSuccess>;
|
|
768
783
|
/**
|
|
769
784
|
* Checks whether or not `other` doesn't equal with self.
|
|
770
785
|
* @param other The other result to compare.
|
|
@@ -794,9 +809,9 @@ interface IResult<T, E> {
|
|
|
794
809
|
* ```
|
|
795
810
|
*/
|
|
796
811
|
match<OkValue, ErrValue>(branches: {
|
|
797
|
-
ok(value: T): OkValue;
|
|
798
|
-
err(error: E): ErrValue;
|
|
799
|
-
}): OkValue
|
|
812
|
+
ok(this: Ok<T>, value: T): OkValue;
|
|
813
|
+
err(this: Err<E>, error: E): ErrValue;
|
|
814
|
+
}): If<Success, OkValue, ErrValue>;
|
|
800
815
|
/**
|
|
801
816
|
* Returns an iterator over the possibly contained value.
|
|
802
817
|
*
|
|
@@ -823,126 +838,124 @@ interface IResult<T, E> {
|
|
|
823
838
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.iter}
|
|
824
839
|
*/
|
|
825
840
|
[Symbol.iterator](): Generator<T>;
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
* Creates an Ok with no value.
|
|
879
|
-
* @return A successful Result.
|
|
880
|
-
*/
|
|
881
|
-
declare function createOk(): ResultOk<unknown>;
|
|
882
|
-
/**
|
|
883
|
-
* Creates an Ok.
|
|
884
|
-
* @typeparam T The result's type.
|
|
885
|
-
* @param x Value to use.
|
|
886
|
-
* @return A successful Result.
|
|
887
|
-
*/
|
|
888
|
-
declare function createOk<T>(x: T): ResultOk<T>;
|
|
889
|
-
|
|
890
|
-
declare class ResultError<E> extends Error {
|
|
891
|
-
readonly value: E;
|
|
892
|
-
constructor(message: string, value: E);
|
|
893
|
-
get name(): string;
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
/**
|
|
897
|
-
* The union of the two variations of `Result`.
|
|
898
|
-
* @typeparam T The result's type.
|
|
899
|
-
* @typeparam E The error's type.
|
|
900
|
-
*/
|
|
901
|
-
type Result<T, E> = Result.Ok<T> | Result.Err<E>;
|
|
902
|
-
declare namespace Result {
|
|
903
|
-
type Resolvable<T, E> = T | Result<T, E>;
|
|
904
|
-
function is<T, E>(value: Result<T, E>): true;
|
|
905
|
-
function is(value: any): value is Result<unknown, unknown>;
|
|
841
|
+
get [Symbol.toStringTag](): If<Success, 'Ok', 'Err'>;
|
|
842
|
+
static ok<T, E = any>(this: void, value: T): Ok<T, E>;
|
|
843
|
+
static err<E, T = any>(this: void, value: E): Err<E, T>;
|
|
844
|
+
/**
|
|
845
|
+
* Checks if the `instance` object is an instance of `Result`, or if it is a `Result`-like object. This override
|
|
846
|
+
* exists to interoperate with other versions of this class, such as the one coming from another version of this
|
|
847
|
+
* library or from a different build.
|
|
848
|
+
*
|
|
849
|
+
* @param instance The instance to check.
|
|
850
|
+
* @returns Whether or not the instance is a `Result`.
|
|
851
|
+
*
|
|
852
|
+
* @example
|
|
853
|
+
* ```typescript
|
|
854
|
+
* import { Result } from '@sapphire/result';
|
|
855
|
+
* const { ok } = require('@sapphire/result');
|
|
856
|
+
*
|
|
857
|
+
* ok(2) instanceof Result; // true
|
|
858
|
+
* ```
|
|
859
|
+
*/
|
|
860
|
+
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
861
|
+
/**
|
|
862
|
+
* @deprecated Use {@link Result.isResult} instead.
|
|
863
|
+
*
|
|
864
|
+
* Checks if the `instance` object is an instance of `Result`, or if it is a `Result`-like object.
|
|
865
|
+
*
|
|
866
|
+
* @param instance The instance to check.
|
|
867
|
+
* @returns true if the instance is a `Result` or a `Result`-like object, false otherwise.
|
|
868
|
+
*
|
|
869
|
+
* @example
|
|
870
|
+
* ```typescript
|
|
871
|
+
* import { Result } from '@sapphire/result';
|
|
872
|
+
* const { ok } = require('@sapphire/result');
|
|
873
|
+
*
|
|
874
|
+
* Result.isResult(ok(2)); // true
|
|
875
|
+
* ```
|
|
876
|
+
*/
|
|
877
|
+
static is(instance: unknown): instance is AnyResult;
|
|
878
|
+
/**
|
|
879
|
+
* Checks if the `instance` object is an instance of `Result`, or if it is a `Result`-like object.
|
|
880
|
+
*
|
|
881
|
+
* @param instance The instance to check.
|
|
882
|
+
* @returns true if the instance is a `Result` or a `Result`-like object, false otherwise.
|
|
883
|
+
*
|
|
884
|
+
* @example
|
|
885
|
+
* ```typescript
|
|
886
|
+
* import { Result } from '@sapphire/result';
|
|
887
|
+
* const { ok } = require('@sapphire/result');
|
|
888
|
+
*
|
|
889
|
+
* Result.isResult(ok(2)); // true
|
|
890
|
+
* ```
|
|
891
|
+
*/
|
|
892
|
+
static isResult(instance: unknown): instance is AnyResult;
|
|
906
893
|
/**
|
|
907
894
|
* Creates a {@link Result} out of a callback.
|
|
895
|
+
*
|
|
908
896
|
* @typeparam T The result's type.
|
|
909
897
|
* @typeparam E The error's type.
|
|
910
898
|
*/
|
|
911
|
-
|
|
899
|
+
static from<T, E = unknown>(this: void, op: ResultResolvable<T, E> | (() => ResultResolvable<T, E>)): Result<T, E>;
|
|
912
900
|
/**
|
|
913
901
|
* Creates a {@link Result} out of a promise or async callback.
|
|
902
|
+
*
|
|
914
903
|
* @typeparam T The result's type.
|
|
915
904
|
* @typeparam E The error's type.
|
|
916
905
|
*/
|
|
917
|
-
|
|
906
|
+
static fromAsync<T, E = unknown>(this: void, op: Awaitable<ResultResolvable<T, E>> | (() => Awaitable<ResultResolvable<T, E>>)): Promise<Result<T, E>>;
|
|
918
907
|
/**
|
|
919
908
|
* Creates an {@link Ok} that is the combination of all collected {@link Ok} values as an array, or the first
|
|
920
909
|
* {@link Err} encountered.
|
|
910
|
+
*
|
|
921
911
|
* @param results An array of {@link Result}s.
|
|
922
912
|
* @returns A new {@link Result}.
|
|
923
913
|
*/
|
|
924
|
-
|
|
914
|
+
static all<const Entries extends readonly AnyResult[]>(this: void, results: Entries): Result<UnwrapOkArray<Entries>, UnwrapErrArray<Entries>[number]>;
|
|
925
915
|
/**
|
|
926
916
|
* Returns the first encountered {@link Ok}, or an {@link Err} that is the combination of all collected error values.
|
|
917
|
+
*
|
|
927
918
|
* @param results An array of {@link Result}s.
|
|
928
919
|
* @returns A new {@link Result}.
|
|
929
920
|
*/
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
type
|
|
934
|
-
type
|
|
935
|
-
type
|
|
936
|
-
type
|
|
937
|
-
type
|
|
921
|
+
static any<const Entries extends readonly AnyResult[]>(this: void, results: Entries): Result<UnwrapOk<Entries[number]>, UnwrapErrArray<Entries>>;
|
|
922
|
+
}
|
|
923
|
+
declare namespace Result {
|
|
924
|
+
type Ok<T, E = any> = Result<T, E, true>;
|
|
925
|
+
type Err<E, T = any> = Result<T, E, false>;
|
|
926
|
+
type Any = Result<any, any>;
|
|
927
|
+
type Resolvable<T, E = any, Success extends boolean = boolean> = T | Result<T, E, Success>;
|
|
928
|
+
type UnwrapOk<T extends AnyResult> = T extends Ok<infer S> ? S : never;
|
|
929
|
+
type UnwrapErr<T extends AnyResult> = T extends Err<infer S> ? S : never;
|
|
930
|
+
type UnwrapOkArray<T extends readonly AnyResult[] | []> = {
|
|
938
931
|
-readonly [P in keyof T]: UnwrapOk<T[P]>;
|
|
939
932
|
};
|
|
940
|
-
type UnwrapErrArray<T extends readonly
|
|
933
|
+
type UnwrapErrArray<T extends readonly AnyResult[] | []> = {
|
|
941
934
|
-readonly [P in keyof T]: UnwrapErr<T[P]>;
|
|
942
935
|
};
|
|
943
936
|
}
|
|
937
|
+
declare const ok: typeof Result.ok;
|
|
938
|
+
declare const err: typeof Result.err;
|
|
939
|
+
type ResultResolvable<T, E = any, Success extends boolean = boolean> = Result.Resolvable<T, E, Success>;
|
|
940
|
+
type Ok<T, E = any> = Result.Ok<T, E>;
|
|
941
|
+
type Err<E, T = any> = Result.Err<E, T>;
|
|
942
|
+
type AnyResult = Result.Any;
|
|
943
|
+
type UnwrapOk<T extends AnyResult> = Result.UnwrapOk<T>;
|
|
944
|
+
type UnwrapErr<T extends AnyResult> = Result.UnwrapErr<T>;
|
|
945
|
+
type UnwrapOkArray<T extends readonly AnyResult[] | []> = Result.UnwrapOkArray<T>;
|
|
946
|
+
type UnwrapErrArray<T extends readonly AnyResult[] | []> = Result.UnwrapErrArray<T>;
|
|
944
947
|
|
|
945
|
-
|
|
948
|
+
declare const ValueProperty: unique symbol;
|
|
949
|
+
declare const ExistsProperty: unique symbol;
|
|
950
|
+
declare class Option<T, Exists extends boolean = boolean> {
|
|
951
|
+
/**
|
|
952
|
+
* Branded value to ensure `Success` is typed correctly.
|
|
953
|
+
* @internal
|
|
954
|
+
*/
|
|
955
|
+
protected __STATUS__: Exists;
|
|
956
|
+
private readonly [ValueProperty];
|
|
957
|
+
private readonly [ExistsProperty];
|
|
958
|
+
private constructor();
|
|
946
959
|
/**
|
|
947
960
|
* Returns `true` if the option is a `Some` value.
|
|
948
961
|
*
|
|
@@ -959,7 +972,7 @@ interface IOption<T> {
|
|
|
959
972
|
*
|
|
960
973
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.is_some}
|
|
961
974
|
*/
|
|
962
|
-
isSome(): this is
|
|
975
|
+
isSome(): this is Some<T>;
|
|
963
976
|
/**
|
|
964
977
|
* Returns `true` if the option is a `Some` and the value inside of it matches a predicate.
|
|
965
978
|
* @param cb The predicate.
|
|
@@ -982,7 +995,8 @@ interface IOption<T> {
|
|
|
982
995
|
*
|
|
983
996
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.is_some_and}
|
|
984
997
|
*/
|
|
985
|
-
isSomeAnd(cb: (value: T) =>
|
|
998
|
+
isSomeAnd<R extends T>(cb: (value: T) => value is R): this is Some<R>;
|
|
999
|
+
isSomeAnd<R extends boolean>(cb: (value: T) => R): this is Some<R> & R;
|
|
986
1000
|
/**
|
|
987
1001
|
* Returns `true` if the option is a `None` value.
|
|
988
1002
|
*
|
|
@@ -999,7 +1013,30 @@ interface IOption<T> {
|
|
|
999
1013
|
*
|
|
1000
1014
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.is_none}
|
|
1001
1015
|
*/
|
|
1002
|
-
isNone(): this is
|
|
1016
|
+
isNone(): this is None;
|
|
1017
|
+
/**
|
|
1018
|
+
* Returns `true` if the option is a `None` value or the value inside of it matches a predicate.
|
|
1019
|
+
*
|
|
1020
|
+
* @example
|
|
1021
|
+
* ```typescript
|
|
1022
|
+
* const x: Option<number> = some(2);
|
|
1023
|
+
* assert.equal(x.isNoneOr((x) => x > 1), true);
|
|
1024
|
+
* ```
|
|
1025
|
+
* @example
|
|
1026
|
+
* ```typescript
|
|
1027
|
+
* const x: Option<number> = some(0);
|
|
1028
|
+
* assert.equal(x.isNoneOr((x) => x > 1), false);
|
|
1029
|
+
* ```
|
|
1030
|
+
* @example
|
|
1031
|
+
* ```typescript
|
|
1032
|
+
* const x: Option<number> = none;
|
|
1033
|
+
* assert.equal(x.isNoneOr((x) => x > 1), true);
|
|
1034
|
+
* ```
|
|
1035
|
+
*
|
|
1036
|
+
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.is_none_or}
|
|
1037
|
+
*/
|
|
1038
|
+
isNoneOr<R extends T>(cb: (value: T) => value is R): this is None | Some<R>;
|
|
1039
|
+
isNoneOr<R extends boolean>(cb: (value: T) => R): If<Exists, R, true>;
|
|
1003
1040
|
/**
|
|
1004
1041
|
* Returns the contained `Some` value.
|
|
1005
1042
|
* @param message The message for the error.
|
|
@@ -1021,7 +1058,7 @@ interface IOption<T> {
|
|
|
1021
1058
|
*
|
|
1022
1059
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.expect}
|
|
1023
1060
|
*/
|
|
1024
|
-
expect(message: string): T
|
|
1061
|
+
expect(message: string): If<Exists, T, never>;
|
|
1025
1062
|
/**
|
|
1026
1063
|
* Returns the contained `Some` value.
|
|
1027
1064
|
*
|
|
@@ -1045,7 +1082,7 @@ interface IOption<T> {
|
|
|
1045
1082
|
*
|
|
1046
1083
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.unwrap}
|
|
1047
1084
|
*/
|
|
1048
|
-
unwrap(): T
|
|
1085
|
+
unwrap(): If<Exists, T, never>;
|
|
1049
1086
|
/**
|
|
1050
1087
|
* Returns the contained `Some` value or a provided default.
|
|
1051
1088
|
*
|
|
@@ -1063,7 +1100,7 @@ interface IOption<T> {
|
|
|
1063
1100
|
*
|
|
1064
1101
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.unwrap_or}
|
|
1065
1102
|
*/
|
|
1066
|
-
unwrapOr<
|
|
1103
|
+
unwrapOr<OutputValue>(defaultValue: OutputValue): If<Exists, T, OutputValue>;
|
|
1067
1104
|
/**
|
|
1068
1105
|
* Returns the contained Some value or computes it from a closure.
|
|
1069
1106
|
*
|
|
@@ -1078,7 +1115,7 @@ interface IOption<T> {
|
|
|
1078
1115
|
*
|
|
1079
1116
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.unwrap_or_else}
|
|
1080
1117
|
*/
|
|
1081
|
-
unwrapOrElse<
|
|
1118
|
+
unwrapOrElse<OutputValue>(cb: () => OutputValue): If<Exists, T, OutputValue>;
|
|
1082
1119
|
/**
|
|
1083
1120
|
* Maps an `Option<T>` to `Option<U>` by applying a function to a contained value.
|
|
1084
1121
|
* @param cb The predicate.
|
|
@@ -1093,7 +1130,7 @@ interface IOption<T> {
|
|
|
1093
1130
|
*
|
|
1094
1131
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.map}
|
|
1095
1132
|
*/
|
|
1096
|
-
map<U>(cb: (value: T) => U):
|
|
1133
|
+
map<U>(cb: (value: T) => U): If<Exists, Some<U>, None>;
|
|
1097
1134
|
/**
|
|
1098
1135
|
* Maps a `Some<T>` to the returned `Option<U>` by applying a function to a contained value, leaving `None`
|
|
1099
1136
|
* untouched.
|
|
@@ -1116,7 +1153,7 @@ interface IOption<T> {
|
|
|
1116
1153
|
*
|
|
1117
1154
|
* @note This is an extension not supported in Rust
|
|
1118
1155
|
*/
|
|
1119
|
-
mapInto<
|
|
1156
|
+
mapInto<OutputOption extends AnyOption>(cb: (value: T) => OutputOption): If<Exists, OutputOption, None>;
|
|
1120
1157
|
/**
|
|
1121
1158
|
* Returns the provided default result (if none), or applies a function to the contained value (if any).
|
|
1122
1159
|
*
|
|
@@ -1138,7 +1175,7 @@ interface IOption<T> {
|
|
|
1138
1175
|
*
|
|
1139
1176
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.map_or}
|
|
1140
1177
|
*/
|
|
1141
|
-
mapOr<
|
|
1178
|
+
mapOr<MappedOutputValue, DefaultOutputValue>(defaultValue: DefaultOutputValue, cb: (value: T) => MappedOutputValue): If<Exists, MappedOutputValue, DefaultOutputValue>;
|
|
1142
1179
|
/**
|
|
1143
1180
|
* Computes a default function result (if none), or applies a different function to the contained value (if any).
|
|
1144
1181
|
* @param defaultValue The default value.
|
|
@@ -1157,7 +1194,7 @@ interface IOption<T> {
|
|
|
1157
1194
|
*
|
|
1158
1195
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.map_or_else}
|
|
1159
1196
|
*/
|
|
1160
|
-
mapOrElse<
|
|
1197
|
+
mapOrElse<OutputValue, OutputNone>(defaultValue: () => OutputNone, cb: (value: T) => OutputValue): If<Exists, OutputValue, OutputNone>;
|
|
1161
1198
|
/**
|
|
1162
1199
|
* Maps a `None` to the returned `Option<U>` by applying a function to a contained value, leaving `Some<T>`
|
|
1163
1200
|
* untouched.
|
|
@@ -1180,7 +1217,7 @@ interface IOption<T> {
|
|
|
1180
1217
|
*
|
|
1181
1218
|
* @note This is an extension not supported in Rust
|
|
1182
1219
|
*/
|
|
1183
|
-
mapNoneInto<
|
|
1220
|
+
mapNoneInto<OutputOption extends AnyOption>(cb: () => OutputOption): If<Exists, Some<T>, OutputOption>;
|
|
1184
1221
|
/**
|
|
1185
1222
|
* Calls the provided closure with a reference to the contained value (if `Some`).
|
|
1186
1223
|
* @param cb The predicate.
|
|
@@ -1218,7 +1255,7 @@ interface IOption<T> {
|
|
|
1218
1255
|
*
|
|
1219
1256
|
* @note This is an extension not supported in Rust
|
|
1220
1257
|
*/
|
|
1221
|
-
inspectAsync(cb: (value: T) => Awaitable<
|
|
1258
|
+
inspectAsync(cb: (value: T) => Awaitable<unknown>): Promise<this>;
|
|
1222
1259
|
/**
|
|
1223
1260
|
* Transforms the `Option<T>` into a `Result<T, E>`, mapping `Some(v)` to `Ok(v)` and `None` to `Err(err)`.
|
|
1224
1261
|
*
|
|
@@ -1239,7 +1276,7 @@ interface IOption<T> {
|
|
|
1239
1276
|
*
|
|
1240
1277
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.ok_or}
|
|
1241
1278
|
*/
|
|
1242
|
-
okOr<
|
|
1279
|
+
okOr<ErrorValue>(error: ErrorValue): If<Exists, Ok<T>, Err<ErrorValue>>;
|
|
1243
1280
|
/**
|
|
1244
1281
|
* Transforms the `Option<T>` into a `Result<T, E>`, mapping `Some(v)` to `Ok(v)` and `None` to `Err(err())`.
|
|
1245
1282
|
* @param cb The error to be used.
|
|
@@ -1257,7 +1294,7 @@ interface IOption<T> {
|
|
|
1257
1294
|
*
|
|
1258
1295
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.ok_or_else}
|
|
1259
1296
|
*/
|
|
1260
|
-
okOrElse<
|
|
1297
|
+
okOrElse<ErrorValue>(cb: () => ErrorValue): If<Exists, Ok<T>, Err<ErrorValue>>;
|
|
1261
1298
|
/**
|
|
1262
1299
|
* Returns an iterator over the possibly contained value.
|
|
1263
1300
|
*
|
|
@@ -1315,7 +1352,7 @@ interface IOption<T> {
|
|
|
1315
1352
|
*
|
|
1316
1353
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.and}
|
|
1317
1354
|
*/
|
|
1318
|
-
and<
|
|
1355
|
+
and<OutputOption extends AnyOption>(option: OutputOption): If<Exists, OutputOption, None>;
|
|
1319
1356
|
/**
|
|
1320
1357
|
* Calls `cb` if the result is `Ok`, otherwise returns the `Err` value of self.
|
|
1321
1358
|
*
|
|
@@ -1335,7 +1372,7 @@ interface IOption<T> {
|
|
|
1335
1372
|
*
|
|
1336
1373
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.and_then}
|
|
1337
1374
|
*/
|
|
1338
|
-
andThen<
|
|
1375
|
+
andThen<OutputOption extends AnyOption>(cb: (value: T) => OutputOption): If<Exists, OutputOption, None>;
|
|
1339
1376
|
/**
|
|
1340
1377
|
* Returns the option if it contains a value, otherwise returns `option`.
|
|
1341
1378
|
* @param option The option.
|
|
@@ -1367,7 +1404,7 @@ interface IOption<T> {
|
|
|
1367
1404
|
*
|
|
1368
1405
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.or}
|
|
1369
1406
|
*/
|
|
1370
|
-
or(option:
|
|
1407
|
+
or<OutputOption extends AnyOption>(option: OutputOption): If<Exists, Some<T>, OutputOption>;
|
|
1371
1408
|
/**
|
|
1372
1409
|
* Calls `cb` if the result is `Ok`, otherwise returns the `Err` value of self.
|
|
1373
1410
|
*
|
|
@@ -1386,7 +1423,7 @@ interface IOption<T> {
|
|
|
1386
1423
|
*
|
|
1387
1424
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.or_else}
|
|
1388
1425
|
*/
|
|
1389
|
-
orElse(cb: () =>
|
|
1426
|
+
orElse<OutputOption extends AnyOption>(cb: () => OutputOption): If<Exists, Some<T>, OutputOption>;
|
|
1390
1427
|
/**
|
|
1391
1428
|
* Returns `Some` if exactly one of self or `option` is `Some`, otherwise returns `None`.
|
|
1392
1429
|
* @param option The option to compare.
|
|
@@ -1418,7 +1455,7 @@ interface IOption<T> {
|
|
|
1418
1455
|
*
|
|
1419
1456
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.xor}
|
|
1420
1457
|
*/
|
|
1421
|
-
xor(option: Option<
|
|
1458
|
+
xor<OtherValue, OtherExists extends boolean>(option: Option<OtherValue, OtherExists>): If<Exists, If<OtherExists, None, Some<T>>, Option<OtherValue, OtherExists>>;
|
|
1422
1459
|
/**
|
|
1423
1460
|
* Returns None if the option is None, otherwise calls `predicate` with the wrapped value and returns:
|
|
1424
1461
|
*
|
|
@@ -1439,6 +1476,7 @@ interface IOption<T> {
|
|
|
1439
1476
|
*
|
|
1440
1477
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.filter}
|
|
1441
1478
|
*/
|
|
1479
|
+
filter<R extends T>(predicate: (value: T) => value is R): Option<R>;
|
|
1442
1480
|
filter(predicate: (value: T) => boolean): Option<T>;
|
|
1443
1481
|
/**
|
|
1444
1482
|
* Returns `true` if the option is a `Some` value containing the given value.
|
|
@@ -1462,7 +1500,7 @@ interface IOption<T> {
|
|
|
1462
1500
|
*
|
|
1463
1501
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.contains}
|
|
1464
1502
|
*/
|
|
1465
|
-
contains(value:
|
|
1503
|
+
contains<const Value extends T>(value: If<Exists, Value, unknown>): this is Some<Value>;
|
|
1466
1504
|
/**
|
|
1467
1505
|
* Zips self with another `Option`.
|
|
1468
1506
|
*
|
|
@@ -1481,7 +1519,7 @@ interface IOption<T> {
|
|
|
1481
1519
|
*
|
|
1482
1520
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.zip}
|
|
1483
1521
|
*/
|
|
1484
|
-
zip<
|
|
1522
|
+
zip<OtherValue, OtherExists extends boolean>(other: Option<OtherValue, OtherExists>): Option<[T, OtherValue], If<Exists, OtherExists, false>>;
|
|
1485
1523
|
/**
|
|
1486
1524
|
* Zips self and another `Option` with function `f`.
|
|
1487
1525
|
*
|
|
@@ -1510,11 +1548,11 @@ interface IOption<T> {
|
|
|
1510
1548
|
*
|
|
1511
1549
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.zip_with}
|
|
1512
1550
|
*/
|
|
1513
|
-
zipWith<
|
|
1551
|
+
zipWith<OtherValue, OtherExists extends boolean, ReturnValue>(other: Option<OtherValue, OtherExists>, f: (value0: T, value1: OtherValue) => ReturnValue): Option<ReturnValue, If<Exists, OtherExists, false>>;
|
|
1514
1552
|
/**
|
|
1515
1553
|
* Unzips an option containing a tuple of two options.
|
|
1516
1554
|
*
|
|
1517
|
-
* If self is `Some(
|
|
1555
|
+
* If self is `Some([a, b])` this method returns `[Some(a), Some(b)]`. Otherwise, `[None, None]` is returned.
|
|
1518
1556
|
*
|
|
1519
1557
|
* @example
|
|
1520
1558
|
* ```typescript
|
|
@@ -1529,7 +1567,7 @@ interface IOption<T> {
|
|
|
1529
1567
|
*
|
|
1530
1568
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.unzip}
|
|
1531
1569
|
*/
|
|
1532
|
-
unzip<
|
|
1570
|
+
unzip<Value0, Value1, Exists extends boolean>(this: Option<readonly [Value0, Value1], Exists>): [Option<Value0, Exists>, Option<Value1, Exists>];
|
|
1533
1571
|
/**
|
|
1534
1572
|
* Transposes an `Option` of a `Result` into a `Result` of an `Option`.
|
|
1535
1573
|
*
|
|
@@ -1544,7 +1582,7 @@ interface IOption<T> {
|
|
|
1544
1582
|
*
|
|
1545
1583
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.transpose}
|
|
1546
1584
|
*/
|
|
1547
|
-
transpose<
|
|
1585
|
+
transpose<ResultValue, ResultError, ResultSuccess extends boolean, Exists extends boolean>(this: Option<Result<ResultValue, ResultError, ResultSuccess>, Exists>): If<Exists, Result<Some<ResultValue>, ResultError, ResultSuccess>, Ok<None>>;
|
|
1548
1586
|
/**
|
|
1549
1587
|
* Converts from `Result<Result<T, E>, E>` to `Result<T, E>`.
|
|
1550
1588
|
*
|
|
@@ -1566,7 +1604,7 @@ interface IOption<T> {
|
|
|
1566
1604
|
*
|
|
1567
1605
|
* @see {@link https://doc.rust-lang.org/std/result/enum.Result.html#method.flatten}
|
|
1568
1606
|
*/
|
|
1569
|
-
flatten<
|
|
1607
|
+
flatten<InnerOption extends AnyOption, Exists extends boolean>(this: Option<InnerOption, Exists>): If<Exists, InnerOption, None>;
|
|
1570
1608
|
/**
|
|
1571
1609
|
* Returns a `Promise` object with the awaited value (if `Some`).
|
|
1572
1610
|
*
|
|
@@ -1578,21 +1616,21 @@ interface IOption<T> {
|
|
|
1578
1616
|
*
|
|
1579
1617
|
* @note This is an extension not supported in Rust
|
|
1580
1618
|
*/
|
|
1581
|
-
intoPromise(): Promise<Option<Awaited<T
|
|
1619
|
+
intoPromise(): Promise<Option<Awaited<T>, Exists>>;
|
|
1582
1620
|
/**
|
|
1583
1621
|
* Checks whether or not `other` equals with self.
|
|
1584
1622
|
* @param other The other option to compare.
|
|
1585
1623
|
*
|
|
1586
1624
|
* @see {@link https://doc.rust-lang.org/std/cmp/trait.PartialEq.html#tymethod.eq}
|
|
1587
1625
|
*/
|
|
1588
|
-
eq(other: Option<
|
|
1626
|
+
eq<OtherValue extends T, OtherExists extends boolean>(other: Option<OtherValue, OtherExists>): this is Option<OtherValue, OtherExists>;
|
|
1589
1627
|
/**
|
|
1590
1628
|
* Checks whether or not `other` doesn't equal with self.
|
|
1591
1629
|
* @param other The other option to compare.
|
|
1592
1630
|
*
|
|
1593
1631
|
* @see {@link https://doc.rust-lang.org/std/cmp/trait.PartialEq.html#method.ne}
|
|
1594
1632
|
*/
|
|
1595
|
-
ne(other: Option<T>): boolean;
|
|
1633
|
+
ne(other: Option<T, boolean>): boolean;
|
|
1596
1634
|
/**
|
|
1597
1635
|
* Runs `ok` function if self is `Ok`, otherwise runs `err` function.
|
|
1598
1636
|
* @param branches The branches to match.
|
|
@@ -1615,9 +1653,9 @@ interface IOption<T> {
|
|
|
1615
1653
|
* ```
|
|
1616
1654
|
*/
|
|
1617
1655
|
match<SomeValue, NoneValue>(branches: {
|
|
1618
|
-
some(value: T): SomeValue;
|
|
1619
|
-
none(): NoneValue;
|
|
1620
|
-
}): SomeValue
|
|
1656
|
+
some(this: Some<T>, value: T): SomeValue;
|
|
1657
|
+
none(this: None): NoneValue;
|
|
1658
|
+
}): If<Exists, SomeValue, NoneValue>;
|
|
1621
1659
|
/**
|
|
1622
1660
|
* Returns an iterator over the possibly contained value.
|
|
1623
1661
|
*
|
|
@@ -1644,214 +1682,115 @@ interface IOption<T> {
|
|
|
1644
1682
|
* @see {@link https://doc.rust-lang.org/std/option/enum.Option.html#method.iter}
|
|
1645
1683
|
*/
|
|
1646
1684
|
[Symbol.iterator](): Generator<T>;
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
okOrElse(cb: () => any): ResultOk<T>;
|
|
1668
|
-
iter(): Generator<T>;
|
|
1669
|
-
and<R extends Option<any>>(option: R): R;
|
|
1670
|
-
andThen<R extends Option<any>>(cb: (value: T) => R): R;
|
|
1671
|
-
or(option: Option<any>): this;
|
|
1672
|
-
orElse(cb?: () => Option<any>): this;
|
|
1673
|
-
xor(option: OptionSome<T>): OptionNone;
|
|
1674
|
-
xor(option: OptionNone): this;
|
|
1675
|
-
xor(option: Option<T>): this | OptionNone;
|
|
1676
|
-
filter(predicate: (value: T) => true): this;
|
|
1677
|
-
filter(predicate: (value: T) => false): OptionNone;
|
|
1678
|
-
filter(predicate: (value: T) => boolean): this | OptionNone;
|
|
1679
|
-
contains(value: T): boolean;
|
|
1680
|
-
zip(other: OptionNone): OptionNone;
|
|
1681
|
-
zip<U>(other: OptionSome<U>): OptionSome<[T, U]>;
|
|
1682
|
-
zip<U>(other: Option<U>): Option<[T, U]>;
|
|
1683
|
-
zipWith<U, R>(other: OptionNone, f: (s: T, o: U) => R): OptionNone;
|
|
1684
|
-
zipWith<U, R>(other: OptionSome<U>, f: (s: T, o: U) => R): OptionSome<R>;
|
|
1685
|
-
zipWith<U, R>(other: Option<U>, f: (s: T, o: U) => R): Option<R>;
|
|
1686
|
-
unzip<I, U>(this: OptionSome<readonly [I, U]>): [OptionSome<I>, OptionSome<U>];
|
|
1687
|
-
transpose<Inner>(this: OptionSome<ResultOk<Inner>>): ResultOk<OptionSome<Inner>>;
|
|
1688
|
-
transpose<Inner>(this: OptionSome<ResultErr<Inner>>): ResultErr<OptionSome<Inner>>;
|
|
1689
|
-
transpose<IT, E>(this: OptionSome<Result<IT, E>>): Result<OptionSome<IT>, E>;
|
|
1690
|
-
flatten<Inner extends Option<any>>(this: OptionSome<Inner>): Inner;
|
|
1691
|
-
intoPromise(): Promise<OptionSome<Awaited<T>>>;
|
|
1692
|
-
eq(other: OptionNone): false;
|
|
1693
|
-
eq(other: Option<T>): boolean;
|
|
1694
|
-
ne(other: OptionNone): true;
|
|
1695
|
-
ne(other: Option<T>): boolean;
|
|
1696
|
-
match<SomeValue, NoneValue>(branches: {
|
|
1697
|
-
some(value: T): SomeValue;
|
|
1698
|
-
none(): NoneValue;
|
|
1699
|
-
}): SomeValue;
|
|
1700
|
-
[Symbol.iterator](): Generator<T>;
|
|
1701
|
-
}
|
|
1702
|
-
declare function createSome<T>(value: T): OptionSome<T>;
|
|
1703
|
-
|
|
1704
|
-
declare class ResultErr<E> implements IResult<any, E> {
|
|
1705
|
-
private readonly error;
|
|
1706
|
-
constructor(error: E);
|
|
1707
|
-
isOk(): false;
|
|
1708
|
-
isOkAnd(cb?: (value: never) => boolean): false;
|
|
1709
|
-
isErr(): this is ResultErr<E>;
|
|
1710
|
-
isErrAnd(cb: (error: E) => boolean): boolean;
|
|
1711
|
-
ok(): OptionNone;
|
|
1712
|
-
err(): OptionSome<E>;
|
|
1713
|
-
map(cb?: (value: never) => unknown): this;
|
|
1714
|
-
mapInto(cb: (value: never) => Result<any, any>): this;
|
|
1715
|
-
mapOr<U>(defaultValue: U, cb?: (value: never) => U): U;
|
|
1716
|
-
mapOrElse<U>(op: (error: E) => U, cb?: (value: never) => U): U;
|
|
1717
|
-
mapErr<F>(cb: (error: E) => F): ResultErr<F>;
|
|
1718
|
-
mapErrInto<R extends Result<any, any>>(cb: (error: E) => R): R;
|
|
1719
|
-
inspect(cb?: (value: never) => void): this;
|
|
1720
|
-
inspectAsync(cb?: (value: never) => Awaitable<unknown>): Promise<this>;
|
|
1721
|
-
inspectErr(cb: (error: E) => void): this;
|
|
1722
|
-
inspectErrAsync(cb: (error: E) => Awaitable<unknown>): Promise<this>;
|
|
1723
|
-
iter(): Generator<never>;
|
|
1724
|
-
expect(message: string): never;
|
|
1725
|
-
expectErr(message?: string): E;
|
|
1726
|
-
unwrap(): never;
|
|
1727
|
-
unwrapErr(): E;
|
|
1728
|
-
unwrapOr<T>(defaultValue: T): T;
|
|
1729
|
-
unwrapOrElse<T>(op: (error: E) => T): T;
|
|
1730
|
-
unwrapRaw(): never;
|
|
1731
|
-
and(result?: Result<any, E>): this;
|
|
1732
|
-
andThen(cb?: (value: never) => Result<any, E>): this;
|
|
1733
|
-
or<R extends Result<any, any>>(result: R): R;
|
|
1734
|
-
orElse<R extends Result<any, any>>(cb: (error: E) => R): R;
|
|
1735
|
-
contains(value?: any): false;
|
|
1736
|
-
containsErr(error: E): boolean;
|
|
1737
|
-
transpose(): OptionSome<this>;
|
|
1738
|
-
flatten(): this;
|
|
1739
|
-
intoOkOrErr(): E;
|
|
1740
|
-
intoPromise(): Promise<ResultErr<Awaited<E>>>;
|
|
1741
|
-
eq(other: ResultOk<any>): false;
|
|
1742
|
-
eq(other: Result<any, E>): boolean;
|
|
1743
|
-
ne(other: ResultOk<any>): true;
|
|
1744
|
-
ne(other: Result<any, E>): boolean;
|
|
1745
|
-
match<OkValue, ErrValue>(branches: {
|
|
1746
|
-
ok(value: never): OkValue;
|
|
1747
|
-
err(error: E): ErrValue;
|
|
1748
|
-
}): ErrValue;
|
|
1749
|
-
[Symbol.iterator](): Generator<never>;
|
|
1750
|
-
}
|
|
1751
|
-
/**
|
|
1752
|
-
* Creates an Err with no error.
|
|
1753
|
-
* @return An erroneous Result.
|
|
1754
|
-
*/
|
|
1755
|
-
declare function createErr(): ResultErr<unknown>;
|
|
1756
|
-
/**
|
|
1757
|
-
* Creates an Err.
|
|
1758
|
-
* @typeparam E The error's type.
|
|
1759
|
-
* @param x Value to use.
|
|
1760
|
-
* @return An erroneous Result.
|
|
1761
|
-
*/
|
|
1762
|
-
declare function createErr<E>(x: E): ResultErr<E>;
|
|
1763
|
-
|
|
1764
|
-
declare class OptionNone implements IOption<any> {
|
|
1765
|
-
isSome(): false;
|
|
1766
|
-
isSomeAnd(cb?: (value: never) => boolean): false;
|
|
1767
|
-
isNone(): this is OptionNone;
|
|
1768
|
-
expect(message: string): never;
|
|
1769
|
-
unwrap(): never;
|
|
1770
|
-
unwrapOr<R>(defaultValue: R): R;
|
|
1771
|
-
unwrapOrElse<R>(cb: () => R): R;
|
|
1772
|
-
map(cb: (value: never) => any): this;
|
|
1773
|
-
mapInto(cb: (value: never) => Option<any>): this;
|
|
1774
|
-
mapOr<R>(defaultValue: R, cb?: (value: never) => R): R;
|
|
1775
|
-
mapOrElse<R>(defaultValue: () => R, cb?: (value: never) => R): R;
|
|
1776
|
-
mapNoneInto<R extends Option<any>>(cb: () => R): R;
|
|
1777
|
-
inspect(cb?: (value: never) => void): this;
|
|
1778
|
-
inspectAsync(cb?: (value: never) => Awaitable<unknown>): Promise<this>;
|
|
1779
|
-
okOr<E>(error: E): ResultErr<E>;
|
|
1780
|
-
okOrElse<E>(cb: () => E): ResultErr<E>;
|
|
1781
|
-
iter(): Generator<never>;
|
|
1782
|
-
and(option: Option<any>): this;
|
|
1783
|
-
andThen(cb: (value: never) => Option<any>): this;
|
|
1784
|
-
or<R extends Option<any>>(option: R): R;
|
|
1785
|
-
orElse<R extends Option<any>>(cb: () => R): R;
|
|
1786
|
-
xor<T>(option: OptionNone): OptionNone;
|
|
1787
|
-
xor<T>(option: OptionSome<T>): OptionSome<T>;
|
|
1788
|
-
xor<T>(option: Option<T>): OptionSome<T> | OptionNone;
|
|
1789
|
-
filter(predicate: (value: never) => boolean): OptionNone;
|
|
1790
|
-
contains(value?: any): false;
|
|
1791
|
-
zip(other: Option<any>): OptionNone;
|
|
1792
|
-
zipWith(other: Option<any>, f: (s: never, o: never) => any): OptionNone;
|
|
1793
|
-
unzip(): [OptionNone, OptionNone];
|
|
1794
|
-
transpose(): ResultOk<OptionNone>;
|
|
1795
|
-
flatten(): OptionNone;
|
|
1796
|
-
intoPromise(): Promise<OptionNone>;
|
|
1797
|
-
eq(other: OptionNone): true;
|
|
1798
|
-
eq(other: OptionSome<any>): false;
|
|
1799
|
-
eq(other: Option<any>): boolean;
|
|
1800
|
-
ne(other: OptionNone): false;
|
|
1801
|
-
ne(other: OptionSome<any>): true;
|
|
1802
|
-
ne(other: Option<any>): boolean;
|
|
1803
|
-
match<SomeValue, NoneValue>(branches: {
|
|
1804
|
-
some(value: never): SomeValue;
|
|
1805
|
-
none(): NoneValue;
|
|
1806
|
-
}): NoneValue;
|
|
1807
|
-
[Symbol.iterator](): Generator<never>;
|
|
1808
|
-
}
|
|
1809
|
-
declare const createNone: OptionNone;
|
|
1810
|
-
|
|
1811
|
-
declare class OptionError extends Error {
|
|
1812
|
-
get name(): string;
|
|
1813
|
-
}
|
|
1814
|
-
|
|
1815
|
-
/**
|
|
1816
|
-
* The union of the two variations of `Option`.
|
|
1817
|
-
* @typeparam T The value's type.
|
|
1818
|
-
*/
|
|
1819
|
-
type Option<T> = Option.Some<T> | Option.None;
|
|
1820
|
-
declare namespace Option {
|
|
1821
|
-
type Resolvable<T> = T | null | undefined | Option<T>;
|
|
1822
|
-
function is<T>(value: Option<T>): true;
|
|
1823
|
-
function is(value: any): value is Option<unknown>;
|
|
1685
|
+
get [Symbol.toStringTag](): If<Exists, 'Some', 'None'>;
|
|
1686
|
+
static readonly none: Option<any, false>;
|
|
1687
|
+
static some<T>(this: void, value: T): Some<T>;
|
|
1688
|
+
/**
|
|
1689
|
+
* Checks if the `instance` object is an instance of `Option`, or if it is a `Option`-like object. This override
|
|
1690
|
+
* exists to interoperate with other versions of this class, such as the one coming from another version of this
|
|
1691
|
+
* library or from a different build.
|
|
1692
|
+
*
|
|
1693
|
+
* @param instance The instance to check.
|
|
1694
|
+
* @returns Whether or not the instance is a `Option`.
|
|
1695
|
+
*
|
|
1696
|
+
* @example
|
|
1697
|
+
* ```typescript
|
|
1698
|
+
* import { Option } from '@sapphire/result';
|
|
1699
|
+
* const { some } = require('@sapphire/result');
|
|
1700
|
+
*
|
|
1701
|
+
* some(2) instanceof Option; // true
|
|
1702
|
+
* ```
|
|
1703
|
+
*/
|
|
1704
|
+
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
1824
1705
|
/**
|
|
1825
|
-
*
|
|
1706
|
+
* @deprecated Use {@link Option.isOption} instead.
|
|
1707
|
+
*
|
|
1708
|
+
* Checks if the `instance` object is an instance of `Option`, or if it is a `Option`-like object.
|
|
1709
|
+
*
|
|
1710
|
+
* @param instance The instance to check.
|
|
1711
|
+
* @returns true if the instance is a `Option` or a `Option`-like object, false otherwise.
|
|
1712
|
+
*
|
|
1713
|
+
* @example
|
|
1714
|
+
* ```typescript
|
|
1715
|
+
* import { Option } from '@sapphire/result';
|
|
1716
|
+
* const { some } = require('@sapphire/result');
|
|
1717
|
+
*
|
|
1718
|
+
* Option.isOption(some(2)); // true
|
|
1719
|
+
* ```
|
|
1720
|
+
*/
|
|
1721
|
+
static is(instance: unknown): instance is AnyOption;
|
|
1722
|
+
/**
|
|
1723
|
+
* Checks if the `instance` object is an instance of `Option`, or if it is a `Option`-like object.
|
|
1724
|
+
*
|
|
1725
|
+
* @param instance The instance to check.
|
|
1726
|
+
* @returns true if the instance is a `Option` or a `Option`-like object, false otherwise.
|
|
1727
|
+
*
|
|
1728
|
+
* @example
|
|
1729
|
+
* ```typescript
|
|
1730
|
+
* import { Option } from '@sapphire/result';
|
|
1731
|
+
* const { some } = require('@sapphire/result');
|
|
1732
|
+
*
|
|
1733
|
+
* Option.isOption(some(2)); // true
|
|
1734
|
+
* ```
|
|
1735
|
+
*/
|
|
1736
|
+
static isOption(instance: unknown): instance is AnyOption;
|
|
1737
|
+
/**
|
|
1738
|
+
* Creates a {@link Result} out of a callback.
|
|
1739
|
+
*
|
|
1826
1740
|
* @typeparam T The result's type.
|
|
1741
|
+
* @typeparam E The error's type.
|
|
1827
1742
|
*/
|
|
1828
|
-
|
|
1743
|
+
static from<T>(this: void, op: OptionResolvable<T> | (() => OptionResolvable<T>)): Option<T>;
|
|
1829
1744
|
/**
|
|
1830
|
-
* Creates
|
|
1745
|
+
* Creates a {@link Result} out of a promise or async callback.
|
|
1746
|
+
*
|
|
1831
1747
|
* @typeparam T The result's type.
|
|
1748
|
+
* @typeparam E The error's type.
|
|
1832
1749
|
*/
|
|
1833
|
-
|
|
1750
|
+
static fromAsync<T>(this: void, op: Awaitable<OptionResolvable<T>> | (() => Awaitable<OptionResolvable<T>>)): Promise<Option<T>>;
|
|
1834
1751
|
/**
|
|
1835
|
-
* Creates
|
|
1836
|
-
* {@link
|
|
1837
|
-
*
|
|
1838
|
-
* @
|
|
1752
|
+
* Creates an {@link Ok} that is the combination of all collected {@link Ok} values as an array, or the first
|
|
1753
|
+
* {@link Err} encountered.
|
|
1754
|
+
*
|
|
1755
|
+
* @param results An array of {@link Result}s.
|
|
1756
|
+
* @returns A new {@link Result}.
|
|
1839
1757
|
*/
|
|
1840
|
-
|
|
1758
|
+
static all<const Entries extends readonly AnyOption[]>(this: void, results: Entries): Option<UnwrapSomeArray<Entries>>;
|
|
1841
1759
|
/**
|
|
1842
1760
|
* Returns the first encountered {@link Some}, or a {@link None} if none was found.
|
|
1761
|
+
*
|
|
1843
1762
|
* @param options An array of {@link Option}s.
|
|
1844
1763
|
* @returns A new {@link Option}.
|
|
1845
1764
|
*/
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
type Some<T> =
|
|
1850
|
-
type None =
|
|
1851
|
-
type
|
|
1852
|
-
type
|
|
1765
|
+
static any<const Entries extends readonly AnyOption[]>(this: void, results: Entries): Option<UnwrapSome<Entries[number]>>;
|
|
1766
|
+
}
|
|
1767
|
+
declare namespace Option {
|
|
1768
|
+
type Some<T> = Option<T, true>;
|
|
1769
|
+
type None<T = any> = Option<T, false>;
|
|
1770
|
+
type Any = Option<any>;
|
|
1771
|
+
type Resolvable<T, Exists extends boolean = boolean> = T | null | undefined | Option<T, Exists>;
|
|
1772
|
+
type UnwrapSome<T extends AnyOption> = T extends Some<infer S> ? S : never;
|
|
1773
|
+
type UnwrapSomeArray<T extends readonly AnyOption[] | []> = {
|
|
1853
1774
|
-readonly [P in keyof T]: UnwrapSome<T[P]>;
|
|
1854
1775
|
};
|
|
1855
1776
|
}
|
|
1777
|
+
declare const some: typeof Option.some;
|
|
1778
|
+
declare const none: Option<any, false>;
|
|
1779
|
+
type OptionResolvable<T, Exists extends boolean = boolean> = Option.Resolvable<T, Exists>;
|
|
1780
|
+
type Some<T> = Option.Some<T>;
|
|
1781
|
+
type None<T = any> = Option.None<T>;
|
|
1782
|
+
type AnyOption = Option.Any;
|
|
1783
|
+
type UnwrapSome<T extends AnyOption> = Option.UnwrapSome<T>;
|
|
1784
|
+
type UnwrapSomeArray<T extends readonly AnyOption[] | []> = Option.UnwrapSomeArray<T>;
|
|
1785
|
+
|
|
1786
|
+
declare class OptionError extends Error {
|
|
1787
|
+
get name(): string;
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
declare class ResultError<E> extends Error {
|
|
1791
|
+
readonly value: E;
|
|
1792
|
+
constructor(message: string, value: E);
|
|
1793
|
+
get name(): string;
|
|
1794
|
+
}
|
|
1856
1795
|
|
|
1857
|
-
export {
|
|
1796
|
+
export { type AnyOption, type AnyResult, type Err, type None, type Ok, Option, OptionError, type OptionResolvable, Result, ResultError, type ResultResolvable, type Some, type UnwrapErr, type UnwrapErrArray, type UnwrapOk, type UnwrapOkArray, type UnwrapSome, type UnwrapSomeArray, err, none, ok, some };
|