Better type inference for the spread function.

This commit is contained in:
Panu Horsmalahti
2015-08-17 14:55:21 +03:00
parent 5109e1269d
commit 3eb67c9e82

35
q/Q.d.ts vendored
View File

@@ -1,7 +1,7 @@
// Type definitions for Q
// Project: https://github.com/kriskowal/q
// Definitions by: Barrie Nemetchek <https://github.com/bnemetchek>, Andrew Gaspar <https://github.com/AndrewGaspar/>, John Reilly <https://github.com/johnnyreilly>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/**
* If value is a Q promise, returns the promise.
@@ -47,10 +47,13 @@ declare module Q {
/**
* Like then, but "spreads" the array into a variadic fulfillment handler. If any of the promises in the array are rejected, instead calls onRejected with the first rejected promise's rejection reason.
*
*
* This is especially useful in conjunction with all
*/
spread<U>(onFulfilled: Function, onRejected?: Function): Promise<U>;
spread<U>(onFulfill: (...args: any[]) => IPromise<U>, onReject?: (reason: any) => IPromise<U>): Promise<U>;
spread<U>(onFulfill: (...args: any[]) => IPromise<U>, onReject?: (reason: any) => U): Promise<U>;
spread<U>(onFulfill: (...args: any[]) => U, onReject?: (reason: any) => IPromise<U>): Promise<U>;
spread<U>(onFulfill: (...args: any[]) => U, onReject?: (reason: any) => U): Promise<U>;
fail<U>(onRejected: (reason: any) => U | IPromise<U>): Promise<U>;
@@ -82,7 +85,7 @@ declare module Q {
/**
* Returns a promise to get the named property of an object. Essentially equivalent to
*
*
* promise.then(function (o) {
* return o[propertyName];
* });
@@ -92,7 +95,7 @@ declare module Q {
delete<U>(propertyName: String): Promise<U>;
/**
* Returns a promise for the result of calling the named method of an object with the given array of arguments. The object itself is this in the function, just like a synchronous method call. Essentially equivalent to
*
*
* promise.then(function (o) {
* return o[methodName].apply(o, args);
* });
@@ -107,13 +110,13 @@ declare module Q {
/**
* Returns a promise for an array of the property names of an object. Essentially equivalent to
*
*
* promise.then(function (o) {
* return Object.keys(o);
* });
*/
keys(): Promise<string[]>;
/**
* A sugar method, equivalent to promise.then(function () { return value; }).
*/
@@ -146,12 +149,12 @@ declare module Q {
* Returns whether a given promise is in the pending state. When the static version is used on non-promises, the result is always false.
*/
isPending(): boolean;
valueOf(): any;
/**
* Returns a "state snapshot" object, which will be in one of three forms:
*
*
* - { state: "pending" }
* - { state: "fulfilled", value: <fulfllment value> }
* - { state: "rejected", reason: <rejection reason> }
@@ -176,12 +179,12 @@ declare module Q {
// If a non-promise value is provided, it will not reject or progress
export function when<T, U>(value: T | IPromise<T>, onFulfilled: (val: T) => U | IPromise<U>, onRejected?: (reason: any) => U | IPromise<U>, onProgress?: (progress: any) => any): Promise<U>;
/**
/**
* Currently "impossible" (and I use the term loosely) to implement due to TypeScript limitations as it is now.
* See: https://github.com/Microsoft/TypeScript/issues/1784 for discussion on it.
*/
// export function try(method: Function, ...args: any[]): Promise<any>;
// export function try(method: Function, ...args: any[]): Promise<any>;
export function fbind<T>(method: (...args: any[]) => T | IPromise<T>, ...args: any[]): (...args: any[]) => Promise<T>;
@@ -206,7 +209,7 @@ declare module Q {
* 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<T>(promises: IPromise<T>[]): Promise<T[]>;
/**
* Returns a promise that is fulfilled with an array of promise state snapshots, but only after all the original promises have settled, i.e. become either fulfilled or rejected.
*/
@@ -215,11 +218,11 @@ declare module Q {
export function allResolved<T>(promises: IPromise<T>[]): Promise<Promise<T>[]>;
/**
* Like then, but "spreads" the array into a variadic fulfillment handler. If any of the promises in the array are rejected, instead calls onRejected with the first rejected promise's rejection reason.
* Like then, but "spreads" the array into a variadic fulfillment handler. If any of the promises in the array are rejected, instead calls onRejected with the first rejected promise's rejection reason.
* This is especially useful in conjunction with all.
*/
export function spread<T, U>(promises: IPromise<T>[], onFulfilled: (...args: T[]) => U | IPromise<U>, onRejected?: (reason: any) => U | IPromise<U>): Promise<U>;
/**
* Returns a promise that will have the same result as promise, except that if promise is not fulfilled or rejected before ms milliseconds, the returned promise will be rejected with an Error with the given message. If message is not supplied, the message will be "Timed out after " + ms + " ms".
*/
@@ -320,7 +323,7 @@ declare module Q {
/**
* Resets the global "Q" variable to the value it has before Q was loaded.
* This will either be undefined if there was no version or the version of Q which was already loaded before.
* @returns { The last version of Q. }
* @returns { The last version of Q. }
*/
export function noConflict(): typeof Q;
}