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 | import Bluebird = require("bluebird");
|
108 |
|
109 | declare global {
|
110 | type IterateFunction<T, R> = (item: T, index: number, arrayLength: number) => R | PromiseLike<R>;
|
111 | |
112 |
|
113 |
|
114 | interface Promise<T> {
|
115 | all(this: Promise<Iterable<{}>>): Bluebird<T>;
|
116 | all(): Bluebird<never>;
|
117 | any<Q>(this: Promise<T & Iterable<Q>>): Bluebird<Q>;
|
118 | any(): Bluebird<never>;
|
119 | asCallback: Bluebird<T>["asCallback"];
|
120 | bind: Bluebird<T>["bind"];
|
121 | call: Bluebird<T>["call"];
|
122 | cancel: Bluebird<T>["cancel"];
|
123 |
|
124 | caught: Bluebird<T>["caught"];
|
125 | delay: Bluebird<T>["delay"];
|
126 | disposer: Bluebird<T>["disposer"];
|
127 | done: Bluebird<T>["done"];
|
128 | each<Q>(this: Promise<T & Iterable<Q>>, iterator: IterateFunction<Q, any>): Bluebird<T>;
|
129 | error: Bluebird<T>["error"];
|
130 | filter<Q>(
|
131 | this: Promise<T & Iterable<Q>>,
|
132 | filterer: IterateFunction<Q, boolean>,
|
133 | options?: Bluebird.ConcurrencyOption,
|
134 | ): Bluebird<T>;
|
135 |
|
136 | get: Bluebird<T>["get"];
|
137 | isCancelled: Bluebird<T>["isCancelled"];
|
138 | isFulfilled: Bluebird<T>["isFulfilled"];
|
139 | isPending: Bluebird<T>["isPending"];
|
140 | isRejected: Bluebird<T>["isRejected"];
|
141 | isResolved: Bluebird<T>["isResolved"];
|
142 | lastly: Bluebird<T>["lastly"];
|
143 | map<U, Q>(
|
144 | this: Promise<T & Iterable<Q>>,
|
145 | mapper: IterateFunction<Q, U>,
|
146 | options?: Bluebird.ConcurrencyOption,
|
147 | ): Bluebird<U[]>;
|
148 | mapSeries<U, Q>(this: Promise<T & Iterable<Q>>, iterator: IterateFunction<Q, U>): Bluebird<U[]>;
|
149 | nodeify: Bluebird<T>["nodeify"];
|
150 | props: Bluebird<T>["props"];
|
151 | race<Q>(this: Promise<T & Iterable<Q>>): Bluebird<Q>;
|
152 | race(): Bluebird<never>;
|
153 | reason: Bluebird<T>["reason"];
|
154 | reduce<U, Q>(
|
155 | this: Promise<T & Iterable<Q>>,
|
156 | reducer: (memo: U, item: Q, index: number, arrayLength: number) => U | PromiseLike<U>,
|
157 | initialValue?: U,
|
158 | ): Bluebird<U>;
|
159 | reflect: Bluebird<T>["reflect"];
|
160 | return: Bluebird<T>["return"];
|
161 | some(this: Promise<Iterable<{}>>, count: number): Bluebird<T>;
|
162 | spread<U, Q>(
|
163 | this: Bluebird<T & Iterable<Q>>,
|
164 | fulfilledHandler: (...values: Q[]) => U | PromiseLike<U>,
|
165 | ): Bluebird<U>;
|
166 | suppressUnhandledRejections: Bluebird<T>["suppressUnhandledRejections"];
|
167 | tap: Bluebird<T>["tap"];
|
168 | tapCatch: Bluebird<T>["tapCatch"];
|
169 |
|
170 | thenReturn: Bluebird<T>["thenReturn"];
|
171 | thenThrow: Bluebird<T>["thenThrow"];
|
172 | catchReturn: Bluebird<T>["catchReturn"];
|
173 | catchThrow: Bluebird<T>["catchThrow"];
|
174 | throw: Bluebird<T>["throw"];
|
175 | timeout: Bluebird<T>["timeout"];
|
176 | toJSON: Bluebird<T>["toJSON"];
|
177 | toString: Bluebird<T>["toString"];
|
178 | value: Bluebird<T>["value"];
|
179 |
|
180 | |
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 | then<TResult1 = T, TResult2 = never>(
|
189 | onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
|
190 | onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null,
|
191 | ): Promise<TResult1 | TResult2>;
|
192 | catch<TResult = never>(
|
193 | onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null,
|
194 | ): Promise<T | TResult>;
|
195 |
|
196 | /*
|
197 | * TypeScript disallows adding overrides via `catch: typeof Bluebird.prototype.catch`. Copy&paste them then.
|
198 | *
|
199 | * @todo Duplication of code is never ideal. See whether there's a better way of achieving this.
|
200 | */
|
201 | catch(
|
202 | predicate: (error: any) => boolean,
|
203 |
|
204 | onReject: (error: any) => T | PromiseLike<T> | void | PromiseLike<void>,
|
205 | ): Bluebird<T>;
|
206 | catch<U>(predicate: (error: any) => boolean, onReject: (error: any) => U | PromiseLike<U>): Bluebird<U | T>;
|
207 | catch<E extends Error>(
|
208 | ErrorClass: new(...args: any[]) => E,
|
209 |
|
210 | onReject: (error: E) => T | PromiseLike<T> | void | PromiseLike<void>,
|
211 | ): Bluebird<T>;
|
212 | catch<E extends Error, U>(
|
213 | ErrorClass: new(...args: any[]) => E,
|
214 | onReject: (error: E) => U | PromiseLike<U>,
|
215 | ): Bluebird<U | T>;
|
216 | // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
217 | catch(predicate: Object, onReject: (error: any) => T | PromiseLike<T> | void | PromiseLike<void>): Bluebird<T>;
|
218 | catch<U>(predicate: Object, onReject: (error: any) => U | PromiseLike<U>): Bluebird<U | T>;
|
219 |
|
220 | /*
|
221 | * See comments above `then` for the reason why this is needed. Taken from es2018.promise.d.ts.
|
222 | *
|
223 | * #std-lib-copy&paste-to-remove
|
224 | *
|
225 | * @todo See the comment near the top of the file about code marked with #std-lib-copy&paste-to-remove
|
226 | */
|
227 | finally(onfinally?: (() => void) | null): Promise<T>;
|
228 | }
|
229 |
|
230 | /*
|
231 | * Patch all static methods and the constructor
|
232 | */
|
233 | interface PromiseConstructor {
|
234 | new<T>(
|
235 | callback: (
|
236 | resolve: (thenableOrResult?: T | PromiseLike<T>) => void,
|
237 | reject: (error?: any) => void,
|
238 | onCancel?: (callback: () => void) => void,
|
239 | ) => void,
|
240 | ): Promise<T>;
|
241 |
|
242 | // all: typeof Bluebird.all; // Provided by lib.es2015.d.ts
|
243 | any: typeof Bluebird.any;
|
244 | attempt: typeof Bluebird.attempt;
|
245 | bind: typeof Bluebird.bind;
|
246 | cast: typeof Bluebird.cast;
|
247 | config: typeof Bluebird.config;
|
248 | coroutine: typeof Bluebird.coroutine;
|
249 | defer: typeof Bluebird.defer;
|
250 | delay: typeof Bluebird.delay;
|
251 | each: typeof Bluebird.each;
|
252 | filter: typeof Bluebird.filter;
|
253 | fromCallback: typeof Bluebird.fromCallback;
|
254 | fromNode: typeof Bluebird.fromNode;
|
255 | is: typeof Bluebird.is;
|
256 | join: typeof Bluebird.join;
|
257 | longStackTraces: typeof Bluebird.longStackTraces;
|
258 | map: typeof Bluebird.map;
|
259 | mapSeries: typeof Bluebird.mapSeries;
|
260 | method: typeof Bluebird.method;
|
261 | onPossiblyUnhandledRejection: typeof Bluebird.onPossiblyUnhandledRejection;
|
262 | promisify: typeof Bluebird.promisify;
|
263 | promisifyAll: typeof Bluebird.promisifyAll;
|
264 | props: typeof Bluebird.props;
|
265 | // race: typeof Bluebird.race; // Provided by lib.es2015.d.ts
|
266 | reduce: typeof Bluebird.reduce;
|
267 | // reject: typeof Bluebird.reject; // Provided by lib.es2015.d.ts
|
268 | // resolve: typeof Bluebird.resolve; // Provided by lib.es2015.d.ts
|
269 | some: typeof Bluebird.some;
|
270 | try: typeof Bluebird.try;
|
271 | using: typeof Bluebird.using;
|
272 |
|
273 | /*
|
274 | * Copy&paste from lib.es2015.promise.d.ts, because Bluebird's typings are not in line with the standard lib.
|
275 | *
|
276 | * #std-lib-copy&paste-to-remove
|
277 | *
|
278 | * @todo See the comment near the top of the file about code marked with #std-lib-copy&paste-to-remove
|
279 | */
|
280 | all<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(
|
281 | values: [
|
282 | T1 | PromiseLike<T1>,
|
283 | T2 | PromiseLike<T2>,
|
284 | T3 | PromiseLike<T3>,
|
285 | T4 | PromiseLike<T4>,
|
286 | T5 | PromiseLike<T5>,
|
287 | T6 | PromiseLike<T6>,
|
288 | T7 | PromiseLike<T7>,
|
289 | T8 | PromiseLike<T8>,
|
290 | T9 | PromiseLike<T9>,
|
291 | T10 | PromiseLike<T10>,
|
292 | ],
|
293 | ): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>;
|
294 | all<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
|
295 | values: [
|
296 | T1 | PromiseLike<T1>,
|
297 | T2 | PromiseLike<T2>,
|
298 | T3 | PromiseLike<T3>,
|
299 | T4 | PromiseLike<T4>,
|
300 | T5 | PromiseLike<T5>,
|
301 | T6 | PromiseLike<T6>,
|
302 | T7 | PromiseLike<T7>,
|
303 | T8 | PromiseLike<T8>,
|
304 | T9 | PromiseLike<T9>,
|
305 | ],
|
306 | ): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>;
|
307 | all<T1, T2, T3, T4, T5, T6, T7, T8>(
|
308 | values: [
|
309 | T1 | PromiseLike<T1>,
|
310 | T2 | PromiseLike<T2>,
|
311 | T3 | PromiseLike<T3>,
|
312 | T4 | PromiseLike<T4>,
|
313 | T5 | PromiseLike<T5>,
|
314 | T6 | PromiseLike<T6>,
|
315 | T7 | PromiseLike<T7>,
|
316 | T8 | PromiseLike<T8>,
|
317 | ],
|
318 | ): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>;
|
319 | all<T1, T2, T3, T4, T5, T6, T7>(
|
320 | values: [
|
321 | T1 | PromiseLike<T1>,
|
322 | T2 | PromiseLike<T2>,
|
323 | T3 | PromiseLike<T3>,
|
324 | T4 | PromiseLike<T4>,
|
325 | T5 | PromiseLike<T5>,
|
326 | T6 | PromiseLike<T6>,
|
327 | T7 | PromiseLike<T7>,
|
328 | ],
|
329 | ): Promise<[T1, T2, T3, T4, T5, T6, T7]>;
|
330 | all<T1, T2, T3, T4, T5, T6>(
|
331 | values: [
|
332 | T1 | PromiseLike<T1>,
|
333 | T2 | PromiseLike<T2>,
|
334 | T3 | PromiseLike<T3>,
|
335 | T4 | PromiseLike<T4>,
|
336 | T5 | PromiseLike<T5>,
|
337 | T6 | PromiseLike<T6>,
|
338 | ],
|
339 | ): Promise<[T1, T2, T3, T4, T5, T6]>;
|
340 | all<T1, T2, T3, T4, T5>(
|
341 | values: [
|
342 | T1 | PromiseLike<T1>,
|
343 | T2 | PromiseLike<T2>,
|
344 | T3 | PromiseLike<T3>,
|
345 | T4 | PromiseLike<T4>,
|
346 | T5 | PromiseLike<T5>,
|
347 | ],
|
348 | ): Promise<[T1, T2, T3, T4, T5]>;
|
349 | all<T1, T2, T3, T4>(
|
350 | values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>],
|
351 | ): Promise<[T1, T2, T3, T4]>;
|
352 | all<T1, T2, T3>(
|
353 | values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>],
|
354 | ): Promise<[T1, T2, T3]>;
|
355 | all<T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
|
356 | all<T>(values: Array<T | PromiseLike<T>>): Promise<T[]>;
|
357 | race<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(
|
358 | values: [
|
359 | T1 | PromiseLike<T1>,
|
360 | T2 | PromiseLike<T2>,
|
361 | T3 | PromiseLike<T3>,
|
362 | T4 | PromiseLike<T4>,
|
363 | T5 | PromiseLike<T5>,
|
364 | T6 | PromiseLike<T6>,
|
365 | T7 | PromiseLike<T7>,
|
366 | T8 | PromiseLike<T8>,
|
367 | T9 | PromiseLike<T9>,
|
368 | T10 | PromiseLike<T10>,
|
369 | ],
|
370 | ): Promise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10>;
|
371 | race<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
|
372 | values: [
|
373 | T1 | PromiseLike<T1>,
|
374 | T2 | PromiseLike<T2>,
|
375 | T3 | PromiseLike<T3>,
|
376 | T4 | PromiseLike<T4>,
|
377 | T5 | PromiseLike<T5>,
|
378 | T6 | PromiseLike<T6>,
|
379 | T7 | PromiseLike<T7>,
|
380 | T8 | PromiseLike<T8>,
|
381 | T9 | PromiseLike<T9>,
|
382 | ],
|
383 | ): Promise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>;
|
384 | race<T1, T2, T3, T4, T5, T6, T7, T8>(
|
385 | values: [
|
386 | T1 | PromiseLike<T1>,
|
387 | T2 | PromiseLike<T2>,
|
388 | T3 | PromiseLike<T3>,
|
389 | T4 | PromiseLike<T4>,
|
390 | T5 | PromiseLike<T5>,
|
391 | T6 | PromiseLike<T6>,
|
392 | T7 | PromiseLike<T7>,
|
393 | T8 | PromiseLike<T8>,
|
394 | ],
|
395 | ): Promise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>;
|
396 | race<T1, T2, T3, T4, T5, T6, T7>(
|
397 | values: [
|
398 | T1 | PromiseLike<T1>,
|
399 | T2 | PromiseLike<T2>,
|
400 | T3 | PromiseLike<T3>,
|
401 | T4 | PromiseLike<T4>,
|
402 | T5 | PromiseLike<T5>,
|
403 | T6 | PromiseLike<T6>,
|
404 | T7 | PromiseLike<T7>,
|
405 | ],
|
406 | ): Promise<T1 | T2 | T3 | T4 | T5 | T6 | T7>;
|
407 | race<T1, T2, T3, T4, T5, T6>(
|
408 | values: [
|
409 | T1 | PromiseLike<T1>,
|
410 | T2 | PromiseLike<T2>,
|
411 | T3 | PromiseLike<T3>,
|
412 | T4 | PromiseLike<T4>,
|
413 | T5 | PromiseLike<T5>,
|
414 | T6 | PromiseLike<T6>,
|
415 | ],
|
416 | ): Promise<T1 | T2 | T3 | T4 | T5 | T6>;
|
417 | race<T1, T2, T3, T4, T5>(
|
418 | values: [
|
419 | T1 | PromiseLike<T1>,
|
420 | T2 | PromiseLike<T2>,
|
421 | T3 | PromiseLike<T3>,
|
422 | T4 | PromiseLike<T4>,
|
423 | T5 | PromiseLike<T5>,
|
424 | ],
|
425 | ): Promise<T1 | T2 | T3 | T4 | T5>;
|
426 | race<T1, T2, T3, T4>(
|
427 | values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>],
|
428 | ): Promise<T1 | T2 | T3 | T4>;
|
429 | race<T1, T2, T3>(
|
430 | values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>],
|
431 | ): Promise<T1 | T2 | T3>;
|
432 | race<T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<T1 | T2>;
|
433 | race<T>(values: Array<T | PromiseLike<T>>): Promise<T>;
|
434 | reject(reason: any): Promise<never>;
|
435 | reject<T>(reason: any): Promise<T>;
|
436 | resolve<T>(value: T | PromiseLike<T>): Promise<T>;
|
437 | resolve(): Promise<void>;
|
438 | }
|
439 |
|
440 | /*
|
441 | * Declare the `Promise` variable. This is needed for es5 only and is a no-op for all other targets.
|
442 | *
|
443 | * #std-lib-copy&paste-to-remove
|
444 | *
|
445 | * @todo See the comment near the top of the file about code marked with #std-lib-copy&paste-to-remove
|
446 | */
|
447 | var Promise: PromiseConstructor;
|
448 | }
|
449 |
|
\ | No newline at end of file |