diff --git a/when/when.d.ts b/when/when.d.ts new file mode 100644 index 0000000000..2389a42439 --- /dev/null +++ b/when/when.d.ts @@ -0,0 +1,64 @@ +// Type definitions for When 2.4.0 +// Project: https://github.com/cujojs/when +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module When { + + /** + * Return a promise that will resolve only once all the supplied promisesOrValues + * have resolved. The resolution value of the returned promise will be an array + * containing the resolution values of each of the promisesOrValues. + * @memberOf when + * + * @param promisesOrValues array of anything, may contain a mix + * of {@link Promise}s and values + */ + function all(promisesOrValues: any[]): Promise; + + /** + * Creates a {promise, resolver} pair, either or both of which + * may be given out safely to consumers. + * The resolver has resolve, reject, and progress. The promise + * has then plus extended promise API. + */ + function defer(): Deferred; + + /** + * Joins multiple promises into a single returned promise. + * @return a promise that will fulfill when *all* the input promises + * have fulfilled, or will reject when *any one* of the input promises rejects. + */ + function join(...promises: Promise[]): Promise; + /** + * Joins multiple promises into a single returned promise. + * @return a promise that will fulfill when *all* the input promises + * have fulfilled, or will reject when *any one* of the input promises rejects. + */ + function join(...promises: any[]): Promise; + + /** + * Returns a resolved promise. The returned promise will be + * - fulfilled with promiseOrValue if it is a value, or + * - if promiseOrValue is a promise + * - fulfilled with promiseOrValue's value after it is fulfilled + * - rejected with promiseOrValue's reason after it is rejected + */ + function resolve(promise: Promise): Promise; + function resolve(value?: T): Promise; + + interface Deferred { + notify(update: any): void; + promise: Promise; + reject(reason: any): void; + resolve(value?: T): void; + } + + interface Promise { + ensure(onFulfilledOrRejected: Function): Promise; + + then(onFulfilled: (value: T) => Promise, onRejected?: (reason: any) => Promise, onProgress?: (update: any) => void): Promise; + then(onFulfilled: (value: T) => Promise, onRejected?: (reason: any) => U, onProgress?: (update: any) => void): Promise; + then(onFulfilled: (value: T) => U, onRejected?: (reason: any) => Promise, onProgress?: (update: any) => void): Promise; + then(onFulfilled: (value: T) => U, onRejected?: (reason: any) => U, onProgress?: (update: any) => void): Promise; + } +}