UNPKG

29 kBTypeScriptView Raw
1// Type definitions for Q 1.5
2// Project: https://github.com/kriskowal/q
3// Definitions by: Barrie Nemetchek <https://github.com/bnemetchek>
4// Andrew Gaspar <https://github.com/AndrewGaspar>
5// John Reilly <https://github.com/johnnyreilly>
6// Michel Boudreau <https://github.com/mboudreau>
7// TeamworkGuy2 <https://github.com/TeamworkGuy2>
8// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
9// TypeScript Version: 2.3
10
11export = Q;
12export as namespace Q;
13
14/**
15 * If value is a Q promise, returns the promise.
16 * If value is a promise from another library it is coerced into a Q promise (where possible).
17 * If value is not a promise, returns a promise that is fulfilled with value.
18 */
19declare function Q<T>(promise: PromiseLike<T> | T): Q.Promise<T>;
20/**
21 * Calling with nothing at all creates a void promise
22 */
23declare function Q(): Q.Promise<void>;
24
25declare namespace Q {
26 export type IWhenable<T> = PromiseLike<T> | T;
27 export type IPromise<T> = PromiseLike<T>;
28
29 export interface Deferred<T> {
30 promise: Promise<T>;
31
32 /**
33 * Calling resolve with a pending promise causes promise to wait on the passed promise, becoming fulfilled with its
34 * fulfillment value or rejected with its rejection reason (or staying pending forever, if the passed promise does).
35 * Calling resolve with a rejected promise causes promise to be rejected with the passed promise's rejection reason.
36 * Calling resolve with a fulfilled promise causes promise to be fulfilled with the passed promise's fulfillment value.
37 * Calling resolve with a non-promise value causes promise to be fulfilled with that value.
38 */
39 resolve(value?: IWhenable<T>): void;
40
41 /**
42 * Calling reject with a reason causes promise to be rejected with that reason.
43 */
44 reject(reason?: any): void;
45
46 /**
47 * Calling notify with a value causes promise to be notified of progress with that value. That is, any onProgress
48 * handlers registered with promise or promises derived from promise will be called with the progress value.
49 */
50 notify(value: any): void;
51
52 /**
53 * Returns a function suitable for passing to a Node.js API. That is, it has a signature (err, result) and will
54 * reject deferred.promise with err if err is given, or fulfill it with result if that is given.
55 */
56 makeNodeResolver(): (reason: any, value: T) => void;
57 }
58
59 export interface Promise<T> {
60 /**
61 * The then method from the Promises/A+ specification, with an additional progress handler.
62 */
63 then<U>(onFulfill?: ((value: T) => IWhenable<U>) | null, onReject?: ((error: any) => IWhenable<U>) | null, onProgress?: ((progress: any) => any) | null): Promise<U>;
64 then<U = T, V = never>(onFulfill?: ((value: T) => IWhenable<U>) | null, onReject?: ((error: any) => IWhenable<V>) | null, onProgress?: ((progress: any) => any) | null): Promise<U | V>;
65 /**
66 * Like a finally clause, allows you to observe either the fulfillment or rejection of a promise, but to do so
67 * without modifying the final value. This is useful for collecting resources regardless of whether a job succeeded,
68 * like closing a database connection, shutting a server down, or deleting an unneeded key from an object.
69 * finally returns a promise, which will become resolved with the same fulfillment value or rejection reason
70 * as promise. However, if callback returns a promise, the resolution of the returned promise will be delayed
71 * until the promise returned from callback is finished. Furthermore, if the returned promise rejects, that
72 * rejection will be passed down the chain instead of the previous result.
73 */
74 finally(finallyCallback: () => any): Promise<T>;
75
76 /**
77 * Alias for finally() (for non-ES5 browsers)
78 */
79 fin(finallyCallback: () => any): Promise<T>;
80
81 /**
82 * Like then, but "spreads" the array into a variadic fulfillment handler. If any of the promises in the array are
83 * rejected, instead calls onRejected with the first rejected promise's rejection reason.
84 * This is especially useful in conjunction with all
85 */
86 spread<U>(onFulfill: (...args: any[]) => IWhenable<U>, onReject?: (reason: any) => IWhenable<U>): Promise<U>;
87
88 /**
89 * A sugar method, equivalent to promise.then(undefined, onRejected).
90 */
91 catch<U>(onRejected: (reason: any) => IWhenable<U>): Promise<U>;
92
93 /**
94 * Alias for catch() (for non-ES5 browsers)
95 */
96 fail<U>(onRejected: (reason: any) => IWhenable<U>): Promise<U>;
97
98 /**
99 * A sugar method, equivalent to promise.then(undefined, undefined, onProgress).
100 */
101 progress(onProgress: (progress: any) => any): Promise<T>;
102
103 /**
104 * Much like then, but with different behavior around unhandled rejection. If there is an unhandled rejection,
105 * either because promise is rejected and no onRejected callback was provided, or because onFulfilled or onRejected
106 * threw an error or returned a rejected promise, the resulting rejection reason is thrown as an exception in a
107 * future turn of the event loop.
108 * This method should be used to terminate chains of promises that will not be passed elsewhere. Since exceptions
109 * thrown in then callbacks are consumed and transformed into rejections, exceptions at the end of the chain are
110 * easy to accidentally, silently ignore. By arranging for the exception to be thrown in a future turn of the
111 * event loop, so that it won't be caught, it causes an onerror event on the browser window, or an uncaughtException
112 * event on Node.js's process object.
113 * Exceptions thrown by done will have long stack traces, if Q.longStackSupport is set to true. If Q.onerror is set,
114 * exceptions will be delivered there instead of thrown in a future turn.
115 * The Golden Rule of done vs. then usage is: either return your promise to someone else, or if the chain ends
116 * with you, call done to terminate it. Terminating with catch is not sufficient because the catch handler may
117 * itself throw an error.
118 */
119 done(onFulfilled?: ((value: T) => any) | null, onRejected?: ((reason: any) => any) | null, onProgress?: ((progress: any) => any) | null): void;
120
121 /**
122 * If callback is a function, assumes it's a Node.js-style callback, and calls it as either callback(rejectionReason)
123 * when/if promise becomes rejected, or as callback(null, fulfillmentValue) when/if promise becomes fulfilled.
124 * If callback is not a function, simply returns promise.
125 */
126 nodeify(callback: (reason: any, value: any) => void): Promise<T>;
127
128 /**
129 * Returns a promise to get the named property of an object. Essentially equivalent to
130 *
131 * @example
132 * promise.then(function (o) { return o[propertyName]; });
133 */
134 get<U>(propertyName: string): Promise<U>;
135
136 set<U>(propertyName: string, value: any): Promise<U>;
137
138 delete<U>(propertyName: string): Promise<U>;
139
140 /**
141 * Returns a promise for the result of calling the named method of an object with the given array of arguments.
142 * The object itself is this in the function, just like a synchronous method call. Essentially equivalent to
143 *
144 * @example
145 * promise.then(function (o) { return o[methodName].apply(o, args); });
146 */
147 post<U>(methodName: string, args: any[]): Promise<U>;
148
149 /**
150 * Returns a promise for the result of calling the named method of an object with the given variadic arguments.
151 * The object itself is this in the function, just like a synchronous method call.
152 */
153 invoke<U>(methodName: string, ...args: any[]): Promise<U>;
154
155 /**
156 * Returns a promise for an array of the property names of an object. Essentially equivalent to
157 *
158 * @example
159 * promise.then(function (o) { return Object.keys(o); });
160 */
161 keys(): Promise<string[]>;
162
163 /**
164 * Returns a promise for the result of calling a function, with the given array of arguments. Essentially equivalent to
165 *
166 * @example
167 * promise.then(function (f) {
168 * return f.apply(undefined, args);
169 * });
170 */
171 fapply<U>(args: any[]): Promise<U>;
172
173 /**
174 * Returns a promise for the result of calling a function, with the given variadic arguments. Has the same return
175 * value/thrown exception translation as explained above for fbind.
176 * In its static form, it is aliased as Q.try, since it has semantics similar to a try block (but handling both
177 * synchronous exceptions and asynchronous rejections). This allows code like
178 *
179 * @example
180 * Q.try(function () {
181 * if (!isConnectedToCloud()) {
182 * throw new Error("The cloud is down!");
183 * }
184 * return syncToCloud();
185 * })
186 * .catch(function (error) {
187 * console.error("Couldn't sync to the cloud", error);
188 * });
189 */
190 fcall<U>(...args: any[]): Promise<U>;
191
192 /**
193 * A sugar method, equivalent to promise.then(function () { return value; }).
194 */
195 thenResolve<U>(value: U): Promise<U>;
196
197 /**
198 * A sugar method, equivalent to promise.then(function () { throw reason; }).
199 */
200 thenReject<U = T>(reason?: any): Promise<U>;
201
202 /**
203 * Attaches a handler that will observe the value of the promise when it becomes fulfilled, returning a promise for
204 * that same value, perhaps deferred but not replaced by the promise returned by the onFulfilled handler.
205 */
206 tap(onFulfilled: (value: T) => any): Promise<T>;
207
208 /**
209 * Returns a promise that will have the same result as promise, except that if promise is not fulfilled or rejected
210 * before ms milliseconds, the returned promise will be rejected with an Error with the given message. If message
211 * is not supplied, the message will be "Timed out after " + ms + " ms".
212 */
213 timeout(ms: number, message?: string): Promise<T>;
214
215 /**
216 * Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least
217 * ms milliseconds have passed.
218 */
219 delay(ms: number): Promise<T>;
220
221 /**
222 * Returns whether a given promise is in the fulfilled state. When the static version is used on non-promises, the
223 * result is always true.
224 */
225 isFulfilled(): boolean;
226
227 /**
228 * Returns whether a given promise is in the rejected state. When the static version is used on non-promises, the
229 * result is always false.
230 */
231 isRejected(): boolean;
232
233 /**
234 * Returns whether a given promise is in the pending state. When the static version is used on non-promises, the
235 * result is always false.
236 */
237 isPending(): boolean;
238
239 valueOf(): any;
240
241 /**
242 * Returns a "state snapshot" object, which will be in one of three forms:
243 *
244 * - { state: "pending" }
245 * - { state: "fulfilled", value: <fulfllment value> }
246 * - { state: "rejected", reason: <rejection reason> }
247 */
248 inspect(): PromiseState<T>;
249 }
250
251 export interface PromiseState<T> {
252 state: "fulfilled" | "rejected" | "pending";
253 value?: T | undefined;
254 reason?: any;
255 }
256
257 /**
258 * Returns a "deferred" object with a:
259 * promise property
260 * resolve(value) method
261 * reject(reason) method
262 * notify(value) method
263 * makeNodeResolver() method
264 */
265 export function defer<T>(): Deferred<T>;
266
267 /**
268 * Calling resolve with a pending promise causes promise to wait on the passed promise, becoming fulfilled with its
269 * fulfillment value or rejected with its rejection reason (or staying pending forever, if the passed promise does).
270 * Calling resolve with a rejected promise causes promise to be rejected with the passed promise's rejection reason.
271 * Calling resolve with a fulfilled promise causes promise to be fulfilled with the passed promise's fulfillment value.
272 * Calling resolve with a non-promise value causes promise to be fulfilled with that value.
273 */
274 export function resolve<T>(object?: IWhenable<T>): Promise<T>;
275
276 /**
277 * Returns a promise that is rejected with reason.
278 */
279 export function reject<T>(reason?: any): Promise<T>;
280
281 // If no value provided, returned promise will be of void type
282 export function when(): Promise<void>;
283
284 // if no fulfill, reject, or progress provided, returned promise will be of same type
285 export function when<T>(value: IWhenable<T>): Promise<T>;
286
287 // If a non-promise value is provided, it will not reject or progress
288 export function when<T, U>(
289 value: IWhenable<T>,
290 onFulfilled: (val: T) => IWhenable<U>,
291 onRejected?: ((reason: any) => IWhenable<U>) | null,
292 onProgress?: ((progress: any) => any) | null
293 ): Promise<U>;
294
295 /**
296 * (Deprecated) Returns a new function that calls a function asynchronously with the given variadic arguments, and returns a promise.
297 * Notably, any synchronous return values or thrown exceptions are transformed, respectively, into fulfillment values
298 * or rejection reasons for the promise returned by this new function.
299 * This method is especially useful in its static form for wrapping functions to ensure that they are always
300 * asynchronous, and that any thrown exceptions (intentional or accidental) are appropriately transformed into a
301 * returned rejected promise. For example:
302 *
303 * @example
304 * var getUserData = Q.fbind(function (userName) {
305 * if (!userName) {
306 * throw new Error("userName must be truthy!");
307 * }
308 * if (localCache.has(userName)) {
309 * return localCache.get(userName);
310 * }
311 * return getUserFromCloud(userName);
312 * });
313 */
314 export function fbind<T>(method: (...args: any[]) => IWhenable<T>, ...args: any[]): (...args: any[]) => Promise<T>;
315
316 /**
317 * Returns a promise for the result of calling a function, with the given variadic arguments. Has the same return
318 * value/thrown exception translation as explained above for fbind.
319 * In its static form, it is aliased as Q.try, since it has semantics similar to a try block (but handling both synchronous
320 * exceptions and asynchronous rejections). This allows code like
321 *
322 * @example
323 * Q.try(function () {
324 * if (!isConnectedToCloud()) {
325 * throw new Error("The cloud is down!");
326 * }
327 * return syncToCloud();
328 * })
329 * .catch(function (error) {
330 * console.error("Couldn't sync to the cloud", error);
331 * });
332 */
333 export function fcall<T>(method: (...args: any[]) => T, ...args: any[]): Promise<T>;
334
335 // but 'try' is a reserved word. This is the only way to get around this
336 /**
337 * Alias for fcall()
338 */
339 export { fcall as try };
340
341 /**
342 * Returns a promise for the result of calling the named method of an object with the given variadic arguments.
343 * The object itself is this in the function, just like a synchronous method call.
344 */
345 export function invoke<T>(obj: any, functionName: string, ...args: any[]): Promise<T>;
346
347 /**
348 * Alias for invoke()
349 */
350 export function send<T>(obj: any, functionName: string, ...args: any[]): Promise<T>;
351
352 /**
353 * Alias for invoke()
354 */
355 export function mcall<T>(obj: any, functionName: string, ...args: any[]): Promise<T>;
356
357 /**
358 * Creates a promise-returning function from a Node.js-style function, optionally binding it with the given
359 * variadic arguments. An example:
360 *
361 * @example
362 * var readFile = Q.nfbind(FS.readFile);
363 * readFile("foo.txt", "utf-8").done(function (text) {
364 * //...
365 * });
366 *
367 * Note that if you have a method that uses the Node.js callback pattern, as opposed to just a function, you will
368 * need to bind its this value before passing it to nfbind, like so:
369 *
370 * @example
371 * var Kitty = mongoose.model("Kitty");
372 * var findKitties = Q.nfbind(Kitty.find.bind(Kitty));
373 *
374 * The better strategy for methods would be to use Q.nbind, as shown below.
375 */
376 export function nfbind<T>(nodeFunction: (...args: any[]) => any, ...args: any[]): (...args: any[]) => Promise<T>;
377
378 /**
379 * Alias for nfbind()
380 */
381 export function denodeify<T>(nodeFunction: (...args: any[]) => any, ...args: any[]): (...args: any[]) => Promise<T>;
382
383 /**
384 * Creates a promise-returning function from a Node.js-style method, optionally binding it with the given
385 * variadic arguments. An example:
386 *
387 * @example
388 * var Kitty = mongoose.model("Kitty");
389 * var findKitties = Q.nbind(Kitty.find, Kitty);
390 * findKitties({ cute: true }).done(function (theKitties) {
391 * //...
392 * });
393 */
394 export function nbind<T>(nodeFunction: (...args: any[]) => any, thisArg: any, ...args: any[]): (...args: any[]) => Promise<T>;
395
396 /**
397 * Calls a Node.js-style function with the given array of arguments, returning a promise that is fulfilled if the
398 * Node.js function calls back with a result, or rejected if it calls back with an error
399 * (or throws one synchronously). An example:
400 *
401 * @example
402 * Q.nfapply(FS.readFile, ["foo.txt", "utf-8"]).done(function (text) {
403 * });
404 *
405 * Note that this example only works because FS.readFile is a function exported from a module, not a method on
406 * an object. For methods, e.g. redisClient.get, you must bind the method to an instance before passing it to
407 * Q.nfapply (or, generally, as an argument to any function call):
408 *
409 * @example
410 * Q.nfapply(redisClient.get.bind(redisClient), ["user:1:id"]).done(function (user) {
411 * });
412 *
413 * The better strategy for methods would be to use Q.npost, as shown below.
414 */
415 export function nfapply<T>(nodeFunction: (...args: any[]) => any, args: any[]): Promise<T>;
416
417 /**
418 * Calls a Node.js-style function with the given variadic arguments, returning a promise that is fulfilled if the
419 * Node.js function calls back with a result, or rejected if it calls back with an error
420 * (or throws one synchronously). An example:
421 *
422 * @example
423 * Q.nfcall(FS.readFile, "foo.txt", "utf-8").done(function (text) {
424 * });
425 *
426 * The same warning about functions vs. methods applies for nfcall as it does for nfapply. In this case, the better
427 * strategy would be to use Q.ninvoke.
428 */
429 export function nfcall<T>(nodeFunction: (...args: any[]) => any, ...args: any[]): Promise<T>;
430
431 /**
432 * Calls a Node.js-style method with the given arguments array, returning a promise that is fulfilled if the method
433 * calls back with a result, or rejected if it calls back with an error (or throws one synchronously). An example:
434 *
435 * @example
436 * Q.npost(redisClient, "get", ["user:1:id"]).done(function (user) {
437 * });
438 */
439 export function npost<T>(nodeModule: any, functionName: string, args: any[]): Promise<T>;
440
441 /**
442 * Calls a Node.js-style method with the given variadic arguments, returning a promise that is fulfilled if the
443 * method calls back with a result, or rejected if it calls back with an error (or throws one synchronously). An example:
444 *
445 * @example
446 * Q.ninvoke(redisClient, "get", "user:1:id").done(function (user) {
447 * });
448 */
449 export function ninvoke<T>(nodeModule: any, functionName: string, ...args: any[]): Promise<T>;
450
451 /**
452 * Alias for ninvoke()
453 */
454 export function nsend<T>(nodeModule: any, functionName: string, ...args: any[]): Promise<T>;
455
456 /**
457 * Returns a promise that is fulfilled with an array containing the fulfillment value of each promise, or is rejected with the same rejection reason as the first promise to be rejected.
458 */
459 export function all<A, B, C, D, E, F>(promises: IWhenable<[IWhenable<A>, IWhenable<B>, IWhenable<C>, IWhenable<D>, IWhenable<E>, IWhenable<F>]>): Promise<[A, B, C, D, E, F]>;
460 /**
461 * Returns a promise that is fulfilled with an array containing the fulfillment value of each promise, or is rejected with the same rejection reason as the first promise to be rejected.
462 */
463 export function all<A, B, C, D, E>(promises: IWhenable<[IWhenable<A>, IWhenable<B>, IWhenable<C>, IWhenable<D>, IWhenable<E>]>): Promise<[A, B, C, D, E]>;
464 /**
465 * Returns a promise that is fulfilled with an array containing the fulfillment value of each promise, or is rejected with the same rejection reason as the first promise to be rejected.
466 */
467 export function all<A, B, C, D>(promises: IWhenable<[IWhenable<A>, IWhenable<B>, IWhenable<C>, IWhenable<D>]>): Promise<[A, B, C, D]>;
468 /**
469 * Returns a promise that is fulfilled with an array containing the fulfillment value of each promise, or is rejected with the same rejection reason as the first promise to be rejected.
470 */
471 export function all<A, B, C>(promises: IWhenable<[IWhenable<A>, IWhenable<B>, IWhenable<C>]>): Promise<[A, B, C]>;
472 /**
473 * Returns a promise that is fulfilled with an array containing the fulfillment value of each promise, or is rejected with the same rejection reason as the first promise to be rejected.
474 */
475 export function all<A, B>(promises: IWhenable<[IPromise<A>, IPromise<B>]>): Promise<[A, B]>;
476 export function all<A, B>(promises: IWhenable<[A, IPromise<B>]>): Promise<[A, B]>;
477 export function all<A, B>(promises: IWhenable<[IPromise<A>, B]>): Promise<[A, B]>;
478 export function all<A, B>(promises: IWhenable<[A, B]>): Promise<[A, B]>;
479 /**
480 * Returns a promise that is fulfilled with an array containing the fulfillment value of each promise, or is rejected with the same rejection reason as the first promise to be rejected.
481 */
482 export function all<T>(promises: IWhenable<Array<IWhenable<T>>>): Promise<T[]>;
483
484 /**
485 * Returns a promise for the first of an array of promises to become settled.
486 */
487 export function race<T>(promises: Array<IWhenable<T>>): Promise<T>;
488
489 /**
490 * Returns a promise that is fulfilled with an array of promise state snapshots, but only after all the original promises
491 * have settled, i.e. become either fulfilled or rejected.
492 */
493 export function allSettled<T>(promises: IWhenable<Array<IWhenable<T>>>): Promise<Array<PromiseState<T>>>;
494
495 /**
496 * Deprecated Alias for allSettled()
497 */
498 export function allResolved<T>(promises: IWhenable<Array<IWhenable<T>>>): Promise<Array<Promise<T>>>;
499
500 /**
501 * Like then, but "spreads" the array into a variadic fulfillment handler. If any of the promises in the array are
502 * rejected, instead calls onRejected with the first rejected promise's rejection reason. This is especially useful
503 * in conjunction with all.
504 */
505 export function spread<T, U>(promises: Array<IWhenable<T>>, onFulfilled: (...args: T[]) => IWhenable<U>, onRejected?: (reason: any) => IWhenable<U>): Promise<U>;
506
507 /**
508 * Returns a promise that will have the same result as promise, except that if promise is not fulfilled or rejected
509 * before ms milliseconds, the returned promise will be rejected with an Error with the given message. If message
510 * is not supplied, the message will be "Timed out after " + ms + " ms".
511 */
512 export function timeout<T>(promise: Promise<T>, ms: number, message?: string): Promise<T>;
513
514 /**
515 * Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed.
516 */
517 export function delay<T>(promiseOrValue: Promise<T> | T, ms: number): Promise<T>;
518 /**
519 * Returns a promise that will be fulfilled with undefined after at least ms milliseconds have passed.
520 */
521 export function delay(ms: number): Promise<void>;
522
523 /**
524 * Returns whether a given promise is in the fulfilled state. When the static version is used on non-promises, the result is always true.
525 */
526 export function isFulfilled(promise: Promise<any>): boolean;
527
528 /**
529 * Returns whether a given promise is in the rejected state. When the static version is used on non-promises, the result is always false.
530 */
531 export function isRejected(promise: Promise<any>): boolean;
532
533 /**
534 * Returns whether a given promise is in the pending state. When the static version is used on non-promises, the result is always false.
535 */
536 export function isPending(promiseOrObject: Promise<any> | any): boolean;
537
538 /**
539 * Synchronously calls resolver(resolve, reject, notify) and returns a promise whose state is controlled by the
540 * functions passed to resolver. This is an alternative promise-creation API that has the same power as the deferred
541 * concept, but without introducing another conceptual entity.
542 * If resolver throws an exception, the returned promise will be rejected with that thrown exception as the rejection reason.
543 * note: In the latest github, this method is called Q.Promise, but if you are using the npm package version 0.9.7
544 * or below, the method is called Q.promise (lowercase vs uppercase p).
545 */
546 export function Promise<T>(resolver: (resolve: (val?: IWhenable<T>) => void, reject: (reason?: any) => void, notify: (progress: any) => void) => void): Promise<T>;
547
548 /**
549 * Creates a new version of func that accepts any combination of promise and non-promise values, converting them to their
550 * fulfillment values before calling the original func. The returned version also always returns a promise: if func does
551 * a return or throw, then Q.promised(func) will return fulfilled or rejected promise, respectively.
552 * This can be useful for creating functions that accept either promises or non-promise values, and for ensuring that
553 * the function always returns a promise even in the face of unintentional thrown exceptions.
554 */
555 export function promised<T>(callback: (...args: any[]) => T): (...args: any[]) => Promise<T>;
556
557 /**
558 * Returns whether the given value is a Q promise.
559 */
560 export function isPromise(object: any): object is Promise<any>;
561
562 /**
563 * Returns whether the given value is a promise (i.e. it's an object with a then function).
564 */
565 export function isPromiseAlike(object: any): object is IPromise<any>;
566
567 /**
568 * If an object is not a promise, it is as "near" as possible.
569 * If a promise is rejected, it is as "near" as possible too.
570 * If it's a fulfilled promise, the fulfillment value is nearer.
571 * If it's a deferred promise and the deferred has been resolved, the
572 * resolution is "nearer".
573 */
574 export function nearer<T>(promise: Promise<T>): T;
575
576 /**
577 * This is an experimental tool for converting a generator function into a deferred function. This has the potential
578 * of reducing nested callbacks in engines that support yield.
579 */
580 export function async<T>(generatorFunction: any): (...args: any[]) => Promise<T>;
581
582 export function nextTick(callback: (...args: any[]) => any): void;
583
584 /**
585 * A settable property that will intercept any uncaught errors that would otherwise be thrown in the next tick of the
586 * event loop, usually as a result of done. Can be useful for getting the full
587 * stack trace of an error in browsers, which is not usually possible with window.onerror.
588 */
589 export let onerror: (reason: any) => void;
590 /**
591 * A settable property that lets you turn on long stack trace support. If turned on, "stack jumps" will be tracked
592 * across asynchronous promise operations, so that if an uncaught error is thrown by done or a rejection reason's stack
593 * property is inspected in a rejection callback, a long stack trace is produced.
594 */
595 export let longStackSupport: boolean;
596
597 /**
598 * Resets the global "Q" variable to the value it has before Q was loaded.
599 * This will either be undefined if there was no version or the version of Q which was already loaded before.
600 * @returns The last version of Q.
601 */
602 export function noConflict(): typeof Q;
603}