-
Notifications
You must be signed in to change notification settings - Fork 30.4k
/
Copy pathindex.d.ts
1365 lines (1241 loc) · 57.2 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
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
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* The code following this comment originates from:
* https://github.com/types/npm-bluebird
*
* Note for browser users: use bluebird-global typings instead of this one
* if you want to use Bluebird via the global Promise symbol.
*
* Licensed under:
* The MIT License (MIT)
*
* Copyright (c) 2016 unional
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
type Constructor<E> = new(...args: any[]) => E;
type CatchFilter<E> = ((error: E) => boolean) | (object & E);
type Resolvable<R> = R | PromiseLike<R>;
type IterateFunction<T, R> = (item: T, index: number, arrayLength: number) => Resolvable<R>;
type PromisifyAllKeys<T> = T extends string ? `${T}Async` : never;
type WithoutLast<T> = T extends [...infer A, any] ? A : [];
type Last<T> = T extends [...any[], infer L] ? L : never;
type ExtractCallbackValueType<T> = T extends (error: any, ...data: infer D) => any ? D : never;
type PromiseMethod<TArgs, TReturn> = TReturn extends never ? never : (...args: WithoutLast<TArgs>) => Promise<TReturn>;
type ExtractAsyncMethod<T> = T extends (...args: infer A) => any
? PromiseMethod<A, ExtractCallbackValueType<Last<Required<A>>>[0]>
: never;
type PromisifyAllItems<T> = {
[K in keyof T as PromisifyAllKeys<K>]: ExtractAsyncMethod<T[K]>;
};
type NonNeverValues<T> = {
[K in keyof T as T[K] extends never ? never : K]: T[K];
};
// Drop `never` values
type PromisifyAll<T> = NonNeverValues<PromisifyAllItems<T>> & T;
declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
readonly [Symbol.toStringTag]: "Object";
/**
* Create a new promise. The passed in function will receive functions
* `resolve` and `reject` as its arguments which can be called to seal the fate of the created promise.
*
* If promise cancellation is enabled, passed in function will receive
* one more function argument `onCancel` that allows to register an optional cancellation callback.
*/
constructor(
callback: (
resolve: (thenableOrResult?: Resolvable<R>) => void,
reject: (error?: any) => void,
onCancel?: (callback: () => void) => void,
) => void,
);
/**
* Promises/A+ `.then()`. Returns a new promise chained from this promise.
*
* The new promise will be rejected or resolved depending on the passed `fulfilledHandler`, `rejectedHandler` and the state of this promise.
*/
// Based on PromiseLike.then, but returns a Bluebird instance.
then<U>(onFulfill?: (value: R) => Resolvable<U>, onReject?: (error: any) => Resolvable<U>): Bluebird<U>; // For simpler signature help.
then<TResult1 = R, TResult2 = never>(
onfulfilled?: ((value: R) => Resolvable<TResult1>) | null,
onrejected?: ((reason: any) => Resolvable<TResult2>) | null,
): Bluebird<TResult1 | TResult2>;
/**
* This is a catch-all exception handler, shortcut for calling `.then(null, handler)` on this promise.
*
* Any exception happening in a `.then`-chain will propagate to nearest `.catch` handler.
*
* Alias `.caught();` for compatibility with earlier ECMAScript version.
*/
catch<U = R>(onReject: ((error: any) => Resolvable<U>) | undefined | null): Bluebird<U | R>;
/**
* This extends `.catch` to work more like catch-clauses in languages like Java or C#.
*
* Instead of manually checking `instanceof` or `.name === "SomeError"`,
* you may specify a number of error constructors which are eligible for this catch handler.
* The catch handler that is first met that has eligible constructors specified, is the one that will be called.
*
* This method also supports predicate-based filters.
* If you pass a predicate function instead of an error constructor, the predicate will receive the error as an argument.
* The return result of the predicate will be used determine whether the error handler should be called.
*
* Alias `.caught();` for compatibility with earlier ECMAScript version.
*/
catch<U, E1, E2, E3, E4, E5>(
filter1: Constructor<E1>,
filter2: Constructor<E2>,
filter3: Constructor<E3>,
filter4: Constructor<E4>,
filter5: Constructor<E5>,
onReject: (error: E1 | E2 | E3 | E4 | E5) => Resolvable<U>,
): Bluebird<U | R>;
catch<U, E1, E2, E3, E4, E5>(
filter1: Constructor<E1> | CatchFilter<E1>,
filter2: Constructor<E2> | CatchFilter<E2>,
filter3: Constructor<E3> | CatchFilter<E3>,
filter4: Constructor<E4> | CatchFilter<E4>,
filter5: Constructor<E5> | CatchFilter<E5>,
onReject: (error: E1 | E2 | E3 | E4 | E5) => Resolvable<U>,
): Bluebird<U | R>;
catch<U, E1, E2, E3, E4>(
filter1: Constructor<E1>,
filter2: Constructor<E2>,
filter3: Constructor<E3>,
filter4: Constructor<E4>,
onReject: (error: E1 | E2 | E3 | E4) => Resolvable<U>,
): Bluebird<U | R>;
catch<U, E1, E2, E3, E4>(
filter1: Constructor<E1> | CatchFilter<E1>,
filter2: Constructor<E2> | CatchFilter<E2>,
filter3: Constructor<E3> | CatchFilter<E3>,
filter4: Constructor<E4> | CatchFilter<E4>,
onReject: (error: E1 | E2 | E3 | E4) => Resolvable<U>,
): Bluebird<U | R>;
catch<U, E1, E2, E3>(
filter1: Constructor<E1>,
filter2: Constructor<E2>,
filter3: Constructor<E3>,
onReject: (error: E1 | E2 | E3) => Resolvable<U>,
): Bluebird<U | R>;
catch<U, E1, E2, E3>(
filter1: Constructor<E1> | CatchFilter<E1>,
filter2: Constructor<E2> | CatchFilter<E2>,
filter3: Constructor<E3> | CatchFilter<E3>,
onReject: (error: E1 | E2 | E3) => Resolvable<U>,
): Bluebird<U | R>;
catch<U, E1, E2>(
filter1: Constructor<E1>,
filter2: Constructor<E2>,
onReject: (error: E1 | E2) => Resolvable<U>,
): Bluebird<U | R>;
catch<U, E1, E2>(
filter1: Constructor<E1> | CatchFilter<E1>,
filter2: Constructor<E2> | CatchFilter<E2>,
onReject: (error: E1 | E2) => Resolvable<U>,
): Bluebird<U | R>;
catch<U, E1>(
filter1: Constructor<E1>,
onReject: (error: E1) => Resolvable<U>,
): Bluebird<U | R>;
catch<U, E1>(
// tslint:disable-next-line:unified-signatures
filter1: Constructor<E1> | CatchFilter<E1>,
onReject: (error: E1) => Resolvable<U>,
): Bluebird<U | R>;
/**
* This is a catch-all exception handler, shortcut for calling `.then(null, handler)` on this promise.
*
* Any exception happening in a `.then`-chain will propagate to nearest `.catch` handler.
*
* Alias `.caught();` for compatibility with earlier ECMAScript version.
*/
caught: Bluebird<R>["catch"];
/**
* Like `.catch` but instead of catching all types of exceptions,
* it only catches those that don't originate from thrown errors but rather from explicit rejections.
*/
error<U>(onReject: (reason: any) => Resolvable<U>): Bluebird<U>;
/**
* Pass a handler that will be called regardless of this promise's fate. Returns a new promise chained from this promise.
*
* There are special semantics for `.finally()` in that the final value cannot be modified from the handler.
*
* Alias `.lastly();` for compatibility with earlier ECMAScript version.
*/
finally(handler: () => Resolvable<any>): Bluebird<R>;
lastly: Bluebird<R>["finally"];
/**
* Create a promise that follows this promise, but is bound to the given `thisArg` value.
* A bound promise will call its handlers with the bound value set to `this`.
*
* Additionally promises derived from a bound promise will also be bound promises with the same `thisArg` binding as the original promise.
*/
bind(thisArg: any): Bluebird<R>;
/**
* Like `.then()`, but any unhandled rejection that ends up here will be thrown as an error.
*/
done<U>(onFulfilled?: (value: R) => Resolvable<U>, onRejected?: (error: any) => Resolvable<U>): void;
/**
* Like `.finally()`, but not called for rejections.
*/
tap(onFulFill: (value: R) => Resolvable<any>): Bluebird<R>;
/**
* Like `.catch()` but rethrows the error
*/
tapCatch(onReject: (error?: any) => Resolvable<any>): Bluebird<R>;
tapCatch<E1, E2, E3, E4, E5>(
filter1: Constructor<E1>,
filter2: Constructor<E2>,
filter3: Constructor<E3>,
filter4: Constructor<E4>,
filter5: Constructor<E5>,
onReject: (error: E1 | E2 | E3 | E4 | E5) => Resolvable<any>,
): Bluebird<R>;
tapCatch<E1, E2, E3, E4, E5>(
filter1: Constructor<E1> | CatchFilter<E1>,
filter2: Constructor<E2> | CatchFilter<E2>,
filter3: Constructor<E3> | CatchFilter<E3>,
filter4: Constructor<E4> | CatchFilter<E4>,
filter5: Constructor<E5> | CatchFilter<E5>,
onReject: (error: E1 | E2 | E3 | E4 | E5) => Resolvable<any>,
): Bluebird<R>;
tapCatch<E1, E2, E3, E4>(
filter1: Constructor<E1>,
filter2: Constructor<E2>,
filter3: Constructor<E3>,
filter4: Constructor<E4>,
onReject: (error: E1 | E2 | E3 | E4) => Resolvable<any>,
): Bluebird<R>;
tapCatch<E1, E2, E3, E4>(
filter1: Constructor<E1> | CatchFilter<E1>,
filter2: Constructor<E2> | CatchFilter<E2>,
filter3: Constructor<E3> | CatchFilter<E3>,
filter4: Constructor<E4> | CatchFilter<E4>,
onReject: (error: E1 | E2 | E3 | E4) => Resolvable<any>,
): Bluebird<R>;
tapCatch<E1, E2, E3>(
filter1: Constructor<E1>,
filter2: Constructor<E2>,
filter3: Constructor<E3>,
onReject: (error: E1 | E2 | E3) => Resolvable<any>,
): Bluebird<R>;
tapCatch<E1, E2, E3>(
filter1: Constructor<E1> | CatchFilter<E1>,
filter2: Constructor<E2> | CatchFilter<E2>,
filter3: Constructor<E3> | CatchFilter<E3>,
onReject: (error: E1 | E2 | E3) => Resolvable<any>,
): Bluebird<R>;
tapCatch<E1, E2>(
filter1: Constructor<E1>,
filter2: Constructor<E2>,
onReject: (error: E1 | E2) => Resolvable<any>,
): Bluebird<R>;
tapCatch<E1, E2>(
filter1: Constructor<E1> | CatchFilter<E1>,
filter2: Constructor<E2> | CatchFilter<E2>,
onReject: (error: E1 | E2) => Resolvable<any>,
): Bluebird<R>;
tapCatch<E1>(
filter1: Constructor<E1>,
onReject: (error: E1) => Resolvable<any>,
): Bluebird<R>;
tapCatch<E1>(
// tslint:disable-next-line:unified-signatures
filter1: Constructor<E1> | CatchFilter<E1>,
onReject: (error: E1) => Resolvable<any>,
): Bluebird<R>;
/**
* Same as calling `Promise.delay(ms, this)`.
*/
delay(ms: number): Bluebird<R>;
/**
* Returns a promise that will be fulfilled with this promise's fulfillment value or rejection reason.
* However, if this promise is not fulfilled or rejected within ms milliseconds, the returned promise
* is rejected with a TimeoutError or the error as the reason.
*
* You may specify a custom error message with the `message` parameter.
*/
timeout(ms: number, message?: string | Error): Bluebird<R>;
/**
* Register a node-style callback on this promise.
*
* When this promise is is either fulfilled or rejected,
* the node callback will be called back with the node.js convention
* where error reason is the first argument and success value is the second argument.
*
* The error argument will be `null` in case of success.
* If the `callback` argument is not a function, this method does not do anything.
*/
nodeify(callback: (err: any, value?: R) => void, options?: Bluebird.SpreadOption): this;
nodeify(...sink: any[]): this;
asCallback(callback: (err: any, value?: R) => void, options?: Bluebird.SpreadOption): this;
asCallback(...sink: any[]): this;
/**
* See if this `promise` has been fulfilled.
*/
isFulfilled(): boolean;
/**
* See if this `promise` has been rejected.
*/
isRejected(): boolean;
/**
* See if this `promise` is still defer.
*/
isPending(): boolean;
/**
* See if this `promise` has been cancelled.
*/
isCancelled(): boolean;
/**
* See if this `promise` is resolved -> either fulfilled or rejected.
*/
isResolved(): boolean;
/**
* Get the fulfillment value of the underlying promise. Throws if the promise isn't fulfilled yet.
*
* throws `TypeError`
*/
value(): R;
/**
* Get the rejection reason for the underlying promise. Throws if the promise isn't rejected yet.
*
* throws `TypeError`
*/
reason(): any;
/**
* Synchronously inspect the state of this `promise`. The `PromiseInspection` will represent the state of
* the promise as snapshotted at the time of calling `.reflect()`.
*/
reflect(): Bluebird<Bluebird.Inspection<R>>;
/**
* This is a convenience method for doing:
*
* <code>
* promise.then(function(obj){
* return obj[propertyName].call(obj, arg...);
* });
* </code>
*/
call<U extends keyof Q, Q>(
this: Bluebird<Q>,
propertyName: U,
...args: any[]
): Bluebird<Q[U] extends (...args: any[]) => any ? ReturnType<Q[U]> : never>;
/**
* This is a convenience method for doing:
*
* <code>
* promise.then(function(obj){
* return obj[propertyName];
* });
* </code>
*/
get<U extends keyof R>(key: U): Bluebird<R[U]>;
/**
* Convenience method for:
*
* <code>
* .then(function() {
* return value;
* });
* </code>
*
* in the case where `value` doesn't change its value. That means `value` is bound at the time of calling `.return()`
*
* Alias `.thenReturn();` for compatibility with earlier ECMAScript version.
*/
return(): Bluebird<void>;
return<U>(value: U): Bluebird<U>;
thenReturn(): Bluebird<void>;
thenReturn<U>(value: U): Bluebird<U>;
/**
* Convenience method for:
*
* <code>
* .then(function() {
* throw reason;
* });
* </code>
* Same limitations apply as with `.return()`.
*
* Alias `.thenThrow();` for compatibility with earlier ECMAScript version.
*/
throw(reason: Error): Bluebird<never>;
thenThrow(reason: Error): Bluebird<never>;
/**
* Convenience method for:
*
* <code>
* .catch(function() {
* return value;
* });
* </code>
*
* in the case where `value` doesn't change its value. That means `value` is bound at the time of calling `.catchReturn()`
*/
catchReturn<U>(value: U): Bluebird<R | U>;
// No need to be specific about Error types in these overrides, since there's no handler function
catchReturn<U>(
filter1: Constructor<Error>,
filter2: Constructor<Error>,
filter3: Constructor<Error>,
filter4: Constructor<Error>,
filter5: Constructor<Error>,
value: U,
): Bluebird<R | U>;
catchReturn<U>(
filter1: Constructor<Error> | CatchFilter<Error>,
filter2: Constructor<Error> | CatchFilter<Error>,
filter3: Constructor<Error> | CatchFilter<Error>,
filter4: Constructor<Error> | CatchFilter<Error>,
filter5: Constructor<Error> | CatchFilter<Error>,
value: U,
): Bluebird<R | U>;
catchReturn<U>(
filter1: Constructor<Error>,
filter2: Constructor<Error>,
filter3: Constructor<Error>,
filter4: Constructor<Error>,
value: U,
): Bluebird<R | U>;
catchReturn<U>(
filter1: Constructor<Error> | CatchFilter<Error>,
filter2: Constructor<Error> | CatchFilter<Error>,
filter3: Constructor<Error> | CatchFilter<Error>,
filter4: Constructor<Error> | CatchFilter<Error>,
value: U,
): Bluebird<R | U>;
catchReturn<U>(
filter1: Constructor<Error>,
filter2: Constructor<Error>,
filter3: Constructor<Error>,
value: U,
): Bluebird<R | U>;
catchReturn<U>(
filter1: Constructor<Error> | CatchFilter<Error>,
filter2: Constructor<Error> | CatchFilter<Error>,
filter3: Constructor<Error> | CatchFilter<Error>,
value: U,
): Bluebird<R | U>;
catchReturn<U>(
filter1: Constructor<Error>,
filter2: Constructor<Error>,
value: U,
): Bluebird<R | U>;
catchReturn<U>(
filter1: Constructor<Error> | CatchFilter<Error>,
filter2: Constructor<Error> | CatchFilter<Error>,
value: U,
): Bluebird<R | U>;
catchReturn<U>(
filter1: Constructor<Error>,
value: U,
): Bluebird<R | U>;
catchReturn<U>(
// tslint:disable-next-line:unified-signatures
filter1: Constructor<Error> | CatchFilter<Error>,
value: U,
): Bluebird<R | U>;
/**
* Convenience method for:
*
* <code>
* .catch(function() {
* throw reason;
* });
* </code>
* Same limitations apply as with `.catchReturn()`.
*/
catchThrow(reason: Error): Bluebird<R>;
// No need to be specific about Error types in these overrides, since there's no handler function
catchThrow(
filter1: Constructor<Error>,
filter2: Constructor<Error>,
filter3: Constructor<Error>,
filter4: Constructor<Error>,
filter5: Constructor<Error>,
reason: Error,
): Bluebird<R>;
catchThrow(
filter1: Constructor<Error> | CatchFilter<Error>,
filter2: Constructor<Error> | CatchFilter<Error>,
filter3: Constructor<Error> | CatchFilter<Error>,
filter4: Constructor<Error> | CatchFilter<Error>,
filter5: Constructor<Error> | CatchFilter<Error>,
reason: Error,
): Bluebird<R>;
catchThrow(
filter1: Constructor<Error>,
filter2: Constructor<Error>,
filter3: Constructor<Error>,
filter4: Constructor<Error>,
reason: Error,
): Bluebird<R>;
catchThrow(
filter1: Constructor<Error> | CatchFilter<Error>,
filter2: Constructor<Error> | CatchFilter<Error>,
filter3: Constructor<Error> | CatchFilter<Error>,
filter4: Constructor<Error> | CatchFilter<Error>,
reason: Error,
): Bluebird<R>;
catchThrow(
filter1: Constructor<Error>,
filter2: Constructor<Error>,
filter3: Constructor<Error>,
reason: Error,
): Bluebird<R>;
catchThrow(
filter1: Constructor<Error> | CatchFilter<Error>,
filter2: Constructor<Error> | CatchFilter<Error>,
filter3: Constructor<Error> | CatchFilter<Error>,
reason: Error,
): Bluebird<R>;
catchThrow(
filter1: Constructor<Error>,
filter2: Constructor<Error>,
reason: Error,
): Bluebird<R>;
catchThrow(
filter1: Constructor<Error> | CatchFilter<Error>,
filter2: Constructor<Error> | CatchFilter<Error>,
reason: Error,
): Bluebird<R>;
catchThrow(
filter1: Constructor<Error>,
reason: Error,
): Bluebird<R>;
catchThrow(
// tslint:disable-next-line:unified-signatures
filter1: Constructor<Error> | CatchFilter<Error>,
reason: Error,
): Bluebird<R>;
/**
* Convert to String.
*/
toString(): string;
/**
* This is implicitly called by `JSON.stringify` when serializing the object. Returns a serialized representation of the `Promise`.
*/
toJSON(): object;
/**
* Like calling `.then`, but the fulfillment value or rejection reason is assumed to be an array, which is flattened to the formal parameters of the handlers.
*/
spread<U, Q>(this: Bluebird<R & Iterable<Q>>, fulfilledHandler: (...values: Q[]) => Resolvable<U>): Bluebird<U>;
/**
* Same as calling `Promise.all(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
*/
all<T1, T2, T3, T4, T5>(
this: Bluebird<[Resolvable<T1>, Resolvable<T2>, Resolvable<T3>, Resolvable<T4>, Resolvable<T5>]>,
): Bluebird<[T1, T2, T3, T4, T5]>;
all<T1, T2, T3, T4>(
this: Bluebird<[Resolvable<T1>, Resolvable<T2>, Resolvable<T3>, Resolvable<T4>]>,
): Bluebird<[T1, T2, T3, T4]>;
all<T1, T2, T3>(this: Bluebird<[Resolvable<T1>, Resolvable<T2>, Resolvable<T3>]>): Bluebird<[T1, T2, T3]>;
all<T1, T2>(this: Bluebird<[Resolvable<T1>, Resolvable<T2>]>): Bluebird<[T1, T2]>;
all<T1>(this: Bluebird<[Resolvable<T1>]>): Bluebird<[T1]>;
all<R>(this: Bluebird<Iterable<Resolvable<R>>>): Bluebird<R[]>;
/**
* Same as calling `Promise.all(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
*/
all(): Bluebird<never>;
/**
* Same as calling `Promise.props(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
*/
props<K, V>(this: PromiseLike<Map<K, Resolvable<V>>>): Bluebird<Map<K, V>>;
props<T>(this: PromiseLike<Bluebird.ResolvableProps<T>>): Bluebird<T>;
/**
* Same as calling `Promise.any(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
*/
any<Q>(this: Bluebird<R & Iterable<Q>>): Bluebird<Q>;
/**
* Same as calling `Promise.any(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
*/
any(): Bluebird<never>;
/**
* Same as calling `Promise.some(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
* Same as calling `Promise.some(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
*/
some<Q>(this: Bluebird<R & Iterable<Q>>, count: number): Bluebird<R>;
/**
* Same as calling `Promise.some(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
* Same as calling `Promise.some(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
*/
some(count: number): Bluebird<never>;
/**
* Same as calling `Promise.race(thisPromise, count)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
*/
race<Q>(this: Bluebird<R & Iterable<Q>>): Bluebird<Q>;
/**
* Same as calling `Promise.race(thisPromise, count)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
*/
race(): Bluebird<never>;
/**
* Same as calling `Bluebird.map(thisPromise, mapper)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
*/
map<U, Q>(
this: Bluebird<R & Iterable<Q>>,
mapper: IterateFunction<Q, U>,
options?: Bluebird.ConcurrencyOption,
): Bluebird<U[]>;
/**
* Same as calling `Promise.reduce(thisPromise, Function reducer, initialValue)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
*/
reduce<U, Q>(
this: Bluebird<R & Iterable<Q>>,
reducer: (memo: U, item: Q, index: number, arrayLength: number) => Resolvable<U>,
initialValue?: Resolvable<U>,
): Bluebird<U>;
/**
* Same as calling ``Promise.filter(thisPromise, filterer)``. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
*/
filter<Q>(
this: Bluebird<R & Iterable<Q>>,
filterer: IterateFunction<Q, boolean>,
options?: Bluebird.ConcurrencyOption,
): Bluebird<R>;
/**
* Same as calling ``Bluebird.each(thisPromise, iterator)``. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
*/
each<Q>(this: Bluebird<R & Iterable<Q>>, iterator: IterateFunction<Q, any>): Bluebird<R>;
/**
* Same as calling ``Bluebird.mapSeries(thisPromise, iterator)``. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
*/
mapSeries<U, Q>(this: Bluebird<R & Iterable<Q>>, iterator: IterateFunction<Q, U>): Bluebird<U[]>;
/**
* Cancel this `promise`. Will not do anything if this promise is already settled or if the cancellation feature has not been enabled
*/
cancel(): void;
/**
* Basically sugar for doing: somePromise.catch(function(){});
*
* Which is needed in case error handlers are attached asynchronously to the promise later, which would otherwise result in premature unhandled rejection reporting.
*/
suppressUnhandledRejections(): void;
/**
* Start the chain of promises with `Promise.try`. Any synchronous exceptions will be turned into rejections on the returned promise.
*
* Note about second argument: if it's specifically a true array, its values become respective arguments for the function call.
* Otherwise it is passed as is as the first argument for the function call.
*
* Alias for `attempt();` for compatibility with earlier ECMAScript version.
*/
static try<R>(fn: () => Resolvable<R>): Bluebird<R>;
static attempt<R>(fn: () => Resolvable<R>): Bluebird<R>;
/**
* Returns a new function that wraps the given function `fn`.
* The new function will always return a promise that is fulfilled with the original functions return values or rejected with thrown exceptions from the original function.
* This method is convenient when a function can sometimes return synchronously or throw synchronously.
*/
static method<R>(fn: () => Resolvable<R>): () => Bluebird<R>;
static method<R, A1>(fn: (arg1: A1) => Resolvable<R>): (arg1: A1) => Bluebird<R>;
static method<R, A1, A2>(fn: (arg1: A1, arg2: A2) => Resolvable<R>): (arg1: A1, arg2: A2) => Bluebird<R>;
static method<R, A1, A2, A3>(
fn: (arg1: A1, arg2: A2, arg3: A3) => Resolvable<R>,
): (arg1: A1, arg2: A2, arg3: A3) => Bluebird<R>;
static method<R, A1, A2, A3, A4>(
fn: (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => Resolvable<R>,
): (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => Bluebird<R>;
static method<R, A1, A2, A3, A4, A5>(
fn: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => Resolvable<R>,
): (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => Bluebird<R>;
static method<R>(fn: (...args: any[]) => Resolvable<R>): (...args: any[]) => Bluebird<R>;
/**
* Create a promise that is resolved with the given `value`. If `value` is a thenable or promise, the returned promise will assume its state.
*/
static resolve(): Bluebird<void>;
static resolve<R>(value: Resolvable<R>): Bluebird<R>;
/**
* Create a promise that is rejected with the given `reason`.
*/
static reject(reason: any): Bluebird<never>;
/**
* @deprecated
* Create a promise with undecided fate and return a `PromiseResolver` to control it. See resolution?: Promise(#promise-resolution).
* @see http://bluebirdjs.com/docs/deprecated-apis.html#promise-resolution
*/
static defer<R>(): Bluebird.Resolver<R>;
/**
* Cast the given `value` to a trusted promise.
*
* If `value` is already a trusted `Promise`, it is returned as is. If `value` is not a thenable, a fulfilled is: Promise returned with `value` as its fulfillment value.
* If `value` is a thenable (Promise-like object, like those returned by jQuery's `$.ajax`), returns a trusted that: Promise assimilates the state of the thenable.
*/
static cast<R>(value: Resolvable<R>): Bluebird<R>;
/**
* Sugar for `Promise.resolve(undefined).bind(thisArg);`. See `.bind()`.
*/
static bind(thisArg: any): Bluebird<void>;
/**
* See if `value` is a trusted Promise.
*/
static is(value: any): boolean;
/**
* Call this right after the library is loaded to enabled long stack traces.
*
* Long stack traces cannot be disabled after being enabled, and cannot be enabled after promises have already been created.
* Long stack traces imply a substantial performance penalty, around 4-5x for throughput and 0.5x for latency.
*/
static longStackTraces(): void;
/**
* Returns a promise that will be resolved with value (or undefined) after given ms milliseconds.
* If value is a promise, the delay will start counting down when it is fulfilled and the returned
* promise will be fulfilled with the fulfillment value of the value promise.
*/
static delay<R>(ms: number, value: Resolvable<R>): Bluebird<R>;
static delay(ms: number): Bluebird<void>;
/**
* Returns a function that will wrap the given `nodeFunction`.
*
* Instead of taking a callback, the returned function will return a promise whose fate is decided by the callback behavior of the given node function.
* The node function should conform to node.js convention of accepting a callback as last argument and
* calling that callback with error as the first argument and success value on the second argument.
*
* If the `nodeFunction` calls its callback with multiple success values, the fulfillment value will be an array of them.
*
* If you pass a `receiver`, the `nodeFunction` will be called as a method on the `receiver`.
*/
static promisify<T>(
func: (callback: (err: any, result?: T) => void) => void,
options?: Bluebird.PromisifyOptions,
): () => Bluebird<T>;
static promisify<T, A1>(
func: (arg1: A1, callback: (err: any, result?: T) => void) => void,
options?: Bluebird.PromisifyOptions,
): (arg1: A1) => Bluebird<T>;
static promisify<T, A1, A2>(
func: (arg1: A1, arg2: A2, callback: (err: any, result?: T) => void) => void,
options?: Bluebird.PromisifyOptions,
): (arg1: A1, arg2: A2) => Bluebird<T>;
static promisify<T, A1, A2, A3>(
func: (arg1: A1, arg2: A2, arg3: A3, callback: (err: any, result?: T) => void) => void,
options?: Bluebird.PromisifyOptions,
): (arg1: A1, arg2: A2, arg3: A3) => Bluebird<T>;
static promisify<T, A1, A2, A3, A4>(
func: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, callback: (err: any, result?: T) => void) => void,
options?: Bluebird.PromisifyOptions,
): (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => Bluebird<T>;
static promisify<T, A1, A2, A3, A4, A5>(
func: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5, callback: (err: any, result?: T) => void) => void,
options?: Bluebird.PromisifyOptions,
): (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => Bluebird<T>;
static promisify(
nodeFunction: (...args: any[]) => void,
options?: Bluebird.PromisifyOptions,
): (...args: any[]) => Bluebird<any>;
/**
* Promisifies the entire object by going through the object's properties and creating an async equivalent of each function on the object and its prototype chain.
*
* The promisified method name will be the original method name postfixed with `Async`. Returns the input object.
*
* Note that the original methods on the object are not overwritten but new methods are created with the `Async`-postfix. For example,
* if you `promisifyAll()` the node.js `fs` object use `fs.statAsync()` to call the promisified `stat` method.
*/
// TODO how to model promisifyAll?
static promisifyAll<T extends object>(target: T, options?: Bluebird.PromisifyAllOptions<T>): PromisifyAll<T>;
/**
* Returns a promise that is resolved by a node style callback function.
*/
static fromNode<T>(
resolver: (callback: (err: any, result?: T) => void) => void,
options?: Bluebird.FromNodeOptions,
): Bluebird<T>;
static fromCallback<T>(
resolver: (callback: (err: any, result?: T) => void) => void,
options?: Bluebird.FromNodeOptions,
): Bluebird<T>;
/**
* Returns a function that can use `yield` to run asynchronous code synchronously.
*
* This feature requires the support of generators which are drafted in the next version of the language.
* Node version greater than `0.11.2` is required and needs to be executed with the `--harmony-generators` (or `--harmony`) command-line switch.
*/
// TODO: After https://github.com/Microsoft/TypeScript/issues/2983 is implemented, we can use
// the return type propagation of generators to automatically infer the return type T.
static coroutine<T>(
generatorFunction: () => IterableIterator<any>,
options?: Bluebird.CoroutineOptions,
): () => Bluebird<T>;
static coroutine<T, A1>(
generatorFunction: (a1: A1) => IterableIterator<any>,
options?: Bluebird.CoroutineOptions,
): (a1: A1) => Bluebird<T>;
static coroutine<T, A1, A2>(
generatorFunction: (a1: A1, a2: A2) => IterableIterator<any>,
options?: Bluebird.CoroutineOptions,
): (a1: A1, a2: A2) => Bluebird<T>;
static coroutine<T, A1, A2, A3>(
generatorFunction: (a1: A1, a2: A2, a3: A3) => IterableIterator<any>,
options?: Bluebird.CoroutineOptions,
): (a1: A1, a2: A2, a3: A3) => Bluebird<T>;
static coroutine<T, A1, A2, A3, A4>(
generatorFunction: (a1: A1, a2: A2, a3: A3, a4: A4) => IterableIterator<any>,
options?: Bluebird.CoroutineOptions,
): (a1: A1, a2: A2, a3: A3, a4: A4) => Bluebird<T>;
static coroutine<T, A1, A2, A3, A4, A5>(
generatorFunction: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => IterableIterator<any>,
options?: Bluebird.CoroutineOptions,
): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) => Bluebird<T>;
static coroutine<T, A1, A2, A3, A4, A5, A6>(
generatorFunction: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => IterableIterator<any>,
options?: Bluebird.CoroutineOptions,
): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) => Bluebird<T>;
static coroutine<T, A1, A2, A3, A4, A5, A6, A7>(
generatorFunction: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7) => IterableIterator<any>,
options?: Bluebird.CoroutineOptions,
): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7) => Bluebird<T>;
static coroutine<T, A1, A2, A3, A4, A5, A6, A7, A8>(
generatorFunction: (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8) => IterableIterator<any>,
options?: Bluebird.CoroutineOptions,
): (a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8) => Bluebird<T>;
/**
* Add `handler` as the handler to call when there is a possibly unhandled rejection. The default handler logs the error stack to stderr or `console.error` in browsers.
*
* Passing no value or a non-function will have the effect of removing any kind of handling for possibly unhandled rejections.
*/
static onPossiblyUnhandledRejection(handler: (reason: any) => any): void;
/**
* Add handler as the handler to call when there is a possibly unhandled rejection.
* The default handler logs the error stack to stderr or console.error in browsers.
*
* Passing no value or a non-function will have the effect of removing any kind of handling for possibly unhandled rejections.
*
* Note: this hook is specific to the bluebird instance its called on, application developers should use global rejection events.
*/
static onPossiblyUnhandledRejection(handler?: (error: Error, promise: Bluebird<any>) => void): void;
/**
* Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled when all the items in the array are fulfilled.
* The promise's fulfillment value is an array with fulfillment values at respective positions to the original array.
* If any promise in the array rejects, the returned promise is rejected with the rejection reason.
*/
// TODO enable more overloads
// array with promises of different types
static all<T1, T2, T3, T4, T5>(
values: [Resolvable<T1>, Resolvable<T2>, Resolvable<T3>, Resolvable<T4>, Resolvable<T5>],
): Bluebird<[T1, T2, T3, T4, T5]>;
static all<T1, T2, T3, T4>(
values: [Resolvable<T1>, Resolvable<T2>, Resolvable<T3>, Resolvable<T4>],
): Bluebird<[T1, T2, T3, T4]>;
static all<T1, T2, T3>(values: [Resolvable<T1>, Resolvable<T2>, Resolvable<T3>]): Bluebird<[T1, T2, T3]>;
static all<T1, T2>(values: [Resolvable<T1>, Resolvable<T2>]): Bluebird<[T1, T2]>;
static all<T1>(values: [Resolvable<T1>]): Bluebird<[T1]>;
// array with values
static all<R>(values: Resolvable<Iterable<Resolvable<R>>>): Bluebird<R[]>;
static allSettled<T1, T2, T3, T4, T5>(
values: [Resolvable<T1>, Resolvable<T2>, Resolvable<T3>, Resolvable<T4>, Resolvable<T5>],
): Bluebird<
[
Bluebird.Inspection<T1>,
Bluebird.Inspection<T2>,
Bluebird.Inspection<T3>,
Bluebird.Inspection<T4>,
Bluebird.Inspection<T5>,
]
>;
static allSettled<T1, T2, T3, T4>(
values: [Resolvable<T1>, Resolvable<T2>, Resolvable<T3>, Resolvable<T4>],
): Bluebird<[Bluebird.Inspection<T1>, Bluebird.Inspection<T2>, Bluebird.Inspection<T3>, Bluebird.Inspection<T4>]>;
static allSettled<T1, T2, T3>(
values: [Resolvable<T1>, Resolvable<T2>, Resolvable<T3>],
): Bluebird<[Bluebird.Inspection<T1>, Bluebird.Inspection<T2>, Bluebird.Inspection<T3>]>;
static allSettled<T1, T2>(
values: [Resolvable<T1>, Resolvable<T2>],
): Bluebird<[Bluebird.Inspection<T1>, Bluebird.Inspection<T2>]>;
static allSettled<T1>(values: [Resolvable<T1>]): Bluebird<[Bluebird.Inspection<T1>]>;
static allSettled<R>(values: Resolvable<Iterable<Resolvable<R>>>): Bluebird<Array<Bluebird.Inspection<R>>>;
/**
* Like ``Promise.all`` but for object properties instead of array items. Returns a promise that is fulfilled when all the properties of the object are fulfilled.
*
* The promise's fulfillment value is an object with fulfillment values at respective keys to the original object.
* If any promise in the object rejects, the returned promise is rejected with the rejection reason.
*
* If `object` is a trusted `Promise`, then it will be treated as a promise for object rather than for its properties.
* All other objects are treated for their properties as is returned by `Object.keys` - the object's own enumerable properties.
*
* *The original object is not modified.*
*/
// map
static props<K, V>(map: Resolvable<Map<K, Resolvable<V>>>): Bluebird<Map<K, V>>;
// trusted promise for object
static props<T>(object: PromiseLike<Bluebird.ResolvableProps<T>>): Bluebird<T>;
// object
static props<T>(object: Bluebird.ResolvableProps<T>): Bluebird<T>; // tslint:disable-line:unified-signatures
/**
* Like `Promise.some()`, with 1 as `count`. However, if the promise fulfills, the fulfillment value is not an array of 1 but the value directly.
*/
static any<R>(values: Resolvable<Iterable<Resolvable<R>>>): Bluebird<R>;
/**
* Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is
* fulfilled or rejected as soon as a promise in the array is fulfilled or rejected with the respective rejection reason or fulfillment value.
*
* **Note** If you pass empty array or a sparse array with no values, or a promise/thenable for such, it will be forever pending.
*/
static race<R>(values: Resolvable<Iterable<Resolvable<R>>>): Bluebird<R>;
/**
* Initiate a competitive race between multiple promises or values (values will become immediately fulfilled promises).
* When `count` amount of promises have been fulfilled, the returned promise is fulfilled with an array that contains the fulfillment values of
* the winners in order of resolution.
*
* If too many promises are rejected so that the promise can never become fulfilled,
* it will be immediately rejected with an array of rejection reasons in the order they were thrown in.
*
* *The original array is not modified.*
*/
static some<R>(values: Resolvable<Iterable<Resolvable<R>>>, count: number): Bluebird<R[]>;
/**
* Promise.join(
* Promise<any>|any values...,
* function handler
* ) -> Promise
* For coordinating multiple concurrent discrete promises.
*
* Note: In 1.x and 0.x Promise.join used to be a Promise.all that took the values in as arguments instead in an array.
* This behavior has been deprecated but is still supported partially - when the last argument is an immediate function value the new semantics will apply
*/
static join<R, A1>(