diff --git a/q/Q-tests.ts b/q/Q-tests.ts index ab613f8aa4..e59f2dc1b3 100644 --- a/q/Q-tests.ts +++ b/q/Q-tests.ts @@ -30,7 +30,7 @@ Q.delay("asdf", 1000).then(x => x.length); var eventualAdd = Q.promised((a?: number, b?: number) => a + b); eventualAdd(Q(1), Q(2)).then(x => x.toExponential()); -var eventually = function (eventually: any) { +function eventually(eventually: T) { return Q.delay(eventually, 1000); }; @@ -42,7 +42,15 @@ Q.when(x, function (x) { Q.all([ eventually(10), eventually(20) -]).spread(function (x: any, y: any) { +]).spread(function (x: number, y: number) { + console.log(x, y); +}); + +Q.all([ + eventually(10), + eventually(20) +]).then(function (results) { + let [x, y] = results; console.log(x, y); }); diff --git a/q/Q.d.ts b/q/Q.d.ts index 4cb4bfad2e..1fa4642121 100644 --- a/q/Q.d.ts +++ b/q/Q.d.ts @@ -203,6 +203,26 @@ declare namespace Q { export function nsend(nodeModule: any, functionName: string, ...args: any[]): Promise; export function nmcall(nodeModule: any, functionName: string, ...args: any[]): Promise; + /** + * 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. + */ + export function all(promises: [IPromise, IPromise, IPromise, IPromise, IPromise, IPromise]): Promise<[A, B, C, D, E, F]>; + /** + * 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. + */ + export function all(promises: [IPromise, IPromise, IPromise, IPromise, IPromise]): Promise<[A, B, C, D, E]>; + /** + * 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. + */ + export function all(promises: [IPromise, IPromise, IPromise, IPromise]): Promise<[A, B, C, D]>; + /** + * 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. + */ + export function all(promises: [IPromise, IPromise, IPromise]): Promise<[A, B, C]>; + /** + * 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. + */ + export function all(promises: [IPromise, IPromise]): Promise<[A, B]>; /** * 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. */