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 | import Bluebird = require("bluebird");
|
114 |
|
115 | declare global {
|
116 | type IterateFunction<T, R> = (item: T, index: number, arrayLength: number) => (R | PromiseLike<R>);
|
117 | |
118 |
|
119 |
|
120 | interface Promise<T> {
|
121 | all(this: Promise<Iterable<{}>>): Bluebird<T>;
|
122 | all(): Bluebird<never>;
|
123 | any<Q>(this: Promise<T & Iterable<Q>>): Bluebird<Q>;
|
124 | any(): Bluebird<never>;
|
125 | asCallback: Bluebird<T>["asCallback"];
|
126 | bind: Bluebird<T>["bind"];
|
127 | call: Bluebird<T>["call"];
|
128 | cancel: Bluebird<T>["cancel"];
|
129 |
|
130 | caught: Bluebird<T>["caught"];
|
131 | delay: Bluebird<T>["delay"];
|
132 | disposer: Bluebird<T>["disposer"];
|
133 | done: Bluebird<T>["done"];
|
134 | each<Q>(this: Promise<T & Iterable<Q>>, iterator: IterateFunction<Q, any>): Bluebird<T>;
|
135 | error: Bluebird<T>["error"];
|
136 | filter<Q>(this: Promise<T & Iterable<Q>>, filterer: IterateFunction<Q, boolean>, options?: Bluebird.ConcurrencyOption): Bluebird<T>;
|
137 |
|
138 | get: Bluebird<T>["get"];
|
139 | isCancelled: Bluebird<T>["isCancelled"];
|
140 | isFulfilled: Bluebird<T>["isFulfilled"];
|
141 | isPending: Bluebird<T>["isPending"];
|
142 | isRejected: Bluebird<T>["isRejected"];
|
143 | isResolved: Bluebird<T>["isResolved"];
|
144 | lastly: Bluebird<T>["lastly"];
|
145 | map<U, Q>(this: Promise<T & Iterable<Q>>, mapper: IterateFunction<Q, U>, options?: Bluebird.ConcurrencyOption): Bluebird<U[]>;
|
146 | mapSeries<U, Q>(this: Promise<T & Iterable<Q>>, iterator: IterateFunction<Q, U>): Bluebird<U[]>;
|
147 | nodeify: Bluebird<T>["nodeify"];
|
148 | props: Bluebird<T>["props"];
|
149 | race<Q>(this: Promise<T & Iterable<Q>>): Bluebird<Q>;
|
150 | race(): Bluebird<never>;
|
151 | reason: Bluebird<T>["reason"];
|
152 | reduce<U, Q>(this: Promise<T & Iterable<Q>>, reducer: (memo: U, item: Q, index: number, arrayLength: number) => (U | PromiseLike<U>), initialValue?: U): Bluebird<U>;
|
153 | reflect: Bluebird<T>["reflect"];
|
154 | return: Bluebird<T>["return"];
|
155 | some(this: Promise<Iterable<{}>>, count: number): Bluebird<T>;
|
156 | spread<U, Q>(this: Bluebird<T & Iterable<Q>>, fulfilledHandler: (...values: Q[]) => (U | PromiseLike<U>)): Bluebird<U>;
|
157 | suppressUnhandledRejections: Bluebird<T>["suppressUnhandledRejections"];
|
158 | tap: Bluebird<T>["tap"];
|
159 | tapCatch: Bluebird<T>["tapCatch"];
|
160 | // then: Bluebird<T>["then"]; // Provided by lib.es5.d.ts
|
161 | thenReturn: Bluebird<T>["thenReturn"];
|
162 | thenThrow: Bluebird<T>["thenThrow"];
|
163 | catchReturn: Bluebird<T>["catchReturn"];
|
164 | catchThrow: Bluebird<T>["catchThrow"];
|
165 | throw: Bluebird<T>["throw"];
|
166 | timeout: Bluebird<T>["timeout"];
|
167 | toJSON: Bluebird<T>["toJSON"];
|
168 | toString: Bluebird<T>["toString"];
|
169 | value: Bluebird<T>["value"];
|
170 |
|
171 | /*
|
172 | * Copy&paste ::then and ::catch from lib.es5.promise.d.ts, because Bluebird's typings are not
|
173 | * in line with the standard lib.
|
174 | *
|
175 | * #std-lib-copy&paste-to-remove
|
176 | *
|
177 | * @todo See the comment near the top of the file about code marked with #std-lib-copy&paste-to-remove
|
178 | */
|
179 | then<TResult1 = T, TResult2 = never>(
|
180 | onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
|
181 | onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
|
182 | ): Promise<TResult1 | TResult2>;
|
183 | catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
|
184 |
|
185 | /*
|
186 | * TypeScript disallows adding overrides via `catch: typeof Bluebird.prototype.catch`. Copy&paste them then.
|
187 | *
|
188 | * @todo Duplication of code is never ideal. See whether there's a better way of achieving this.
|
189 | */
|
190 | catch(predicate: (error: any) => boolean, onReject: (error: any) => T | PromiseLike<T> | void | PromiseLike<void>): Bluebird<T>;
|
191 | catch<U>(predicate: (error: any) => boolean, onReject: (error: any) => U | PromiseLike<U>): Bluebird<U | T>;
|
192 | catch<E extends Error>(ErrorClass: new (...args: any[]) => E, onReject: (error: E) => T | PromiseLike<T> | void | PromiseLike<void>): Bluebird<T>;
|
193 | catch<E extends Error, U>(ErrorClass: new (...args: any[]) => E, onReject: (error: E) => U | PromiseLike<U>): Bluebird<U | T>;
|
194 | catch(predicate: Object, onReject: (error: any) => T | PromiseLike<T> | void | PromiseLike<void>): Bluebird<T>;
|
195 | catch<U>(predicate: Object, onReject: (error: any) => U | PromiseLike<U>): Bluebird<U | T>;
|
196 |
|
197 | /*
|
198 | * See comments above `then` for the reason why this is needed. Taken from es2018.promise.d.ts.
|
199 | *
|
200 | * #std-lib-copy&paste-to-remove
|
201 | *
|
202 | * @todo See the comment near the top of the file about code marked with #std-lib-copy&paste-to-remove
|
203 | */
|
204 | finally(onfinally?: (() => void) | null): Promise<T>;
|
205 | }
|
206 |
|
207 | /*
|
208 | * Patch all static methods and the constructor
|
209 | */
|
210 | interface PromiseConstructor {
|
211 | new <T>(callback: (resolve: (thenableOrResult?: T | PromiseLike<T>) => void, reject: (error?: any) => void, onCancel?: (callback: () => void) => void) => void): Promise<T>;
|
212 |
|
213 | // all: typeof Bluebird.all; // Provided by lib.es2015.d.ts
|
214 | any: typeof Bluebird.any;
|
215 | attempt: typeof Bluebird.attempt;
|
216 | bind: typeof Bluebird.bind;
|
217 | cast: typeof Bluebird.cast;
|
218 | config: typeof Bluebird.config;
|
219 | coroutine: typeof Bluebird.coroutine;
|
220 | defer: typeof Bluebird.defer;
|
221 | delay: typeof Bluebird.delay;
|
222 | each: typeof Bluebird.each;
|
223 | filter: typeof Bluebird.filter;
|
224 | fromCallback: typeof Bluebird.fromCallback;
|
225 | fromNode: typeof Bluebird.fromNode;
|
226 | is: typeof Bluebird.is;
|
227 | join: typeof Bluebird.join;
|
228 | longStackTraces: typeof Bluebird.longStackTraces;
|
229 | map: typeof Bluebird.map;
|
230 | mapSeries: typeof Bluebird.mapSeries;
|
231 | method: typeof Bluebird.method;
|
232 | onPossiblyUnhandledRejection: typeof Bluebird.onPossiblyUnhandledRejection;
|
233 | promisify: typeof Bluebird.promisify;
|
234 | promisifyAll: typeof Bluebird.promisifyAll;
|
235 | props: typeof Bluebird.props;
|
236 | // race: typeof Bluebird.race; // Provided by lib.es2015.d.ts
|
237 | reduce: typeof Bluebird.reduce;
|
238 | // reject: typeof Bluebird.reject; // Provided by lib.es2015.d.ts
|
239 | // resolve: typeof Bluebird.resolve; // Provided by lib.es2015.d.ts
|
240 | some: typeof Bluebird.some;
|
241 | try: typeof Bluebird.try;
|
242 | using: typeof Bluebird.using;
|
243 |
|
244 | /*
|
245 | * Copy&paste from lib.es2015.promise.d.ts, because Bluebird's typings are not in line with the standard lib.
|
246 | *
|
247 | * #std-lib-copy&paste-to-remove
|
248 | *
|
249 | * @todo See the comment near the top of the file about code marked with #std-lib-copy&paste-to-remove
|
250 | */
|
251 | all<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>;
|
252 | all<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>;
|
253 | all<T1, T2, T3, T4, T5, T6, T7, T8>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>;
|
254 | all<T1, T2, T3, T4, T5, T6, T7>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>;
|
255 | all<T1, T2, T3, T4, T5, T6>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>;
|
256 | all<T1, T2, T3, T4, T5>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>;
|
257 | all<T1, T2, T3, T4>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike <T4>]): Promise<[T1, T2, T3, T4]>;
|
258 | all<T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>;
|
259 | all<T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
|
260 | all<T>(values: (T | PromiseLike<T>)[]): Promise<T[]>;
|
261 | race<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10>;
|
262 | race<T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>;
|
263 | race<T1, T2, T3, T4, T5, T6, T7, T8>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>;
|
264 | race<T1, T2, T3, T4, T5, T6, T7>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<T1 | T2 | T3 | T4 | T5 | T6 | T7>;
|
265 | race<T1, T2, T3, T4, T5, T6>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<T1 | T2 | T3 | T4 | T5 | T6>;
|
266 | race<T1, T2, T3, T4, T5>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<T1 | T2 | T3 | T4 | T5>;
|
267 | race<T1, T2, T3, T4>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<T1 | T2 | T3 | T4>;
|
268 | race<T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<T1 | T2 | T3>;
|
269 | race<T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<T1 | T2>;
|
270 | race<T>(values: (T | PromiseLike<T>)[]): Promise<T>;
|
271 | reject(reason: any): Promise<never>;
|
272 | reject<T>(reason: any): Promise<T>;
|
273 | resolve<T>(value: T | PromiseLike<T>): Promise<T>;
|
274 | resolve(): Promise<void>;
|
275 | }
|
276 |
|
277 | /*
|
278 | * Declare the `Promise` variable. This is needed for es5 only and is a no-op for all other targets.
|
279 | *
|
280 | * #std-lib-copy&paste-to-remove
|
281 | *
|
282 | * @todo See the comment near the top of the file about code marked with #std-lib-copy&paste-to-remove
|
283 | */
|
284 | var Promise: PromiseConstructor;
|
285 | }
|
286 |
|
\ | No newline at end of file |