Add overloads for all to support typed arrays (#9622)

Adds overloads for arrays of up to 6 elements, before
falling back to old behaviour.
This commit is contained in:
Benjamin Fox
2016-06-14 00:47:56 +09:00
committed by Masahiro Wakame
parent 0c1189250f
commit 623f30ab19
2 changed files with 30 additions and 2 deletions
+10 -2
View File
@@ -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<T>(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);
});
Vendored
+20
View File
@@ -203,6 +203,26 @@ declare namespace Q {
export function nsend<T>(nodeModule: any, functionName: string, ...args: any[]): Promise<T>;
export function nmcall<T>(nodeModule: any, functionName: string, ...args: any[]): Promise<T>;
/**
* 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<A, B, C, D, E, F>(promises: [IPromise<A>, IPromise<B>, IPromise<C>, IPromise<D>, IPromise<E>, IPromise<F>]): 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<A, B, C, D, E>(promises: [IPromise<A>, IPromise<B>, IPromise<C>, IPromise<D>, IPromise<E>]): 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<A, B, C, D>(promises: [IPromise<A>, IPromise<B>, IPromise<C>, IPromise<D>]): 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<A, B, C>(promises: [IPromise<A>, IPromise<B>, IPromise<C>]): 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<A, B>(promises: [IPromise<A>, IPromise<B>]): 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.
*/