// Type definitions for When 2.4.0 // Project: https://github.com/cujojs/when // Definitions by: Derek Cicerone , Wim Looman // Definitions: https://github.com/borisyankov/DefinitelyTyped declare function When(value: When.Promise): When.Promise; declare function When(value: When.Thenable): When.Promise; declare function When(value: T): When.Promise; declare function When(value: When.Promise, transform: (val: T) => U): When.Promise; declare function When(value: When.Thenable, transform: (val: T) => U): When.Promise; declare function When(value: T, transform: (val: T) => U): When.Promise; declare module When { function attempt(f: () => T): Promise; function attempt(f: (a: A) => T, a: Promise): Promise; function attempt(f: (a: A) => T, a: A): Promise; function attempt(f: (a: A, b: B) => T, a: Promise, b: Promise): Promise; function attempt(f: (a: A, b: B) => T, a: Promise, b: B): Promise; function attempt(f: (a: A, b: B) => T, a: A, b: Promise): Promise; function attempt(f: (a: A, b: B) => T, a: A, b: B): Promise; function attempt(f: (a: A, b: B, c: C) => T, a: Promise, b: Promise, c: Promise): Promise; function attempt(f: (a: A, b: B, c: C) => T, a: Promise, b: Promise, c: C): Promise; function attempt(f: (a: A, b: B, c: C) => T, a: Promise, b: B, c: Promise): Promise; function attempt(f: (a: A, b: B, c: C) => T, a: Promise, b: B, c: C): Promise; function attempt(f: (a: A, b: B, c: C) => T, a: A, b: Promise, c: Promise): Promise; function attempt(f: (a: A, b: B, c: C) => T, a: A, b: Promise, c: C): Promise; function attempt(f: (a: A, b: B, c: C) => T, a: A, b: B, c: Promise): Promise; function attempt(f: (a: A, b: B, c: C) => T, a: A, b: B, c: C): Promise; function lift(f: () => T): () => Promise; function lift(f: (a: A) => T): (a: Promise) => Promise; function lift(f: (a: A, b: B) => T): (a: Promise, b: Promise) => Promise; function lift(f: (a: A, b: B, c: C) => T): (a: Promise, b: Promise, c: Promise) => Promise; function promise(resolver: (resolve: (value: T) => void, reject: (reason: any) => void) => void): Promise; function reject(reason: any): Promise; /** * 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(foreign: Thenable): Promise; function resolve(value?: T): Promise; interface Deferred { notify(update: any): void; promise: Promise; reject(reason: any): void; resolve(value?: T): void; resolve(value?: Promise): void; } interface Promise { catch(onRejected?: (reason: any) => Promise): Promise; catch(onRejected?: (reason: any) => U): Promise; catch(filter: (reason: any) => boolean, onRejected?: (reason: any) => Promise): Promise; catch(filter: (reason: any) => boolean, onRejected?: (reason: any) => U): Promise; // Make sure you test any usage of these overloads, exceptionType must // be a constructor with prototype set to an instance of Error. catch(exceptionType: any, onRejected?: (reason: any) => Promise): Promise; catch(exceptionType: any, onRejected?: (reason: any) => U): Promise; finally(onFulfilledOrRejected: Function): Promise; ensure(onFulfilledOrRejected: Function): Promise; inspect(): Snapshot; yield(value: Promise): Promise; yield(value: U): Promise; else(value: T): Promise; orElse(value: T): Promise; tap(onFulfilledSideEffect: (value: T) => void): Promise; delay(milliseconds: number): Promise; timeout(milliseconds: number, reason?: any): Promise; with(thisArg: any): Promise; withThis(thisArg: any): Promise; otherwise(onRejected?: (reason: any) => Promise): Promise; otherwise(onRejected?: (reason: any) => U): Promise; otherwise(predicate: (reason: any) => boolean, onRejected?: (reason: any) => Promise): Promise; otherwise(predicate: (reason: any) => boolean, onRejected?: (reason: any) => U): Promise; // Make sure you test any usage of these overloads, exceptionType must // be a constructor with prototype set to an instance of Error. otherwise(exceptionType: any, onRejected?: (reason: any) => Promise): Promise; otherwise(exceptionType: any, onRejected?: (reason: any) => U): 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; done(onFulfilled: (value: T) => void, onRejected?: (reason: any) => void): void; fold(combine: (value1: T, value2: V) => Promise, value2: V): Promise; fold(combine: (value1: T, value2: V) => Promise, value2: Promise): Promise; fold(combine: (value1: T, value2: V) => U, value2: V): Promise; fold(combine: (value1: T, value2: V) => U, value2: Promise): Promise; } interface Thenable { then(onFulfilled: (value: T) => U, onRejected?: (reason: any) => U): Thenable; } interface Snapshot { state: string; value?: T; reason?: any; } } declare module "when" { export = When; }