// Type definitions for Q
// Project: https://github.com/kriskowal/q
// Definitions by: Barrie Nemetchek, Andrew Gaspar
// Definitions: https://github.com/borisyankov/DefinitelyTyped
///
declare function Q(promise: Q.IPromise): Q.Promise;
declare function Q(promise: JQueryPromise): Q.Promise;
declare function Q(value: T): Q.Promise;
declare module Q {
interface IPromise {
then(onFulfill: (value: T) => IPromise, onReject?: (reason: any) => IPromise): IPromise;
then(onFulfill: (value: T) => IPromise, onReject?: (reason: any) => U): IPromise;
then(onFulfill: (value: T) => U, onReject?: (reason: any) => IPromise): IPromise;
then(onFulfill: (value: T) => U, onReject?: (reason: any) => U): IPromise;
}
interface Deferred {
promise: Promise;
resolve(value: T): void;
reject(reason: any): void;
notify(value: any): void;
makeNodeResolver(): (reason: any, value: T) => void;
}
interface Promise {
fin(finallyCallback: () => any): Promise;
finally(finallyCallback: () => any): Promise;
then(onFulfill: (value: T) => IPromise, onReject?: (reason: any) => IPromise, onProgress?: Function): Promise;
then(onFulfill: (value: T) => IPromise, onReject?: (reason: any) => U, onProgress?: Function): Promise;
then(onFulfill: (value: T) => U, onReject?: (reason: any) => IPromise, onProgress?: Function): Promise;
then(onFulfill: (value: T) => U, onReject?: (reason: any) => U, onProgress?: Function): Promise;
spread(onFulfilled: Function, onRejected?: Function): Promise;
fail(onRejected: (reason: any) => U): Promise;
fail(onRejected: (reason: any) => IPromise): Promise;
catch(onRejected: (reason: any) => U): Promise;
catch(onRejected: (reason: any) => IPromise): Promise;
progress(onProgress: (progress: any) => any): Promise;
done(onFulfilled?: (value: T) => any, onRejected?: (reason: any) => any, onProgress?: (progress: any) => any): void;
get(propertyName: String): Promise;
set(propertyName: String, value: any): Promise;
delete(propertyName: String): Promise;
post(methodName: String, args: any[]): Promise;
invoke(methodName: String, ...args: any[]): Promise;
fapply(args: any[]): Promise;
fcall(...args: any[]): Promise;
keys(): Promise;
thenResolve(value: U): Promise;
thenReject(reason: any): Promise;
timeout(ms: number, message?: string): Promise;
delay(ms: number): Promise;
isFulfilled(): boolean;
isRejected(): boolean;
isPending(): boolean;
valueOf(): any;
inspect(): PromiseState;
}
interface PromiseState {
state: string /* "fulfilled", "rejected", "pending" */;
value?: T;
reason?: any;
}
// if no fulfill, reject, or progress provided, returned promise will be of same type
export function when(value: IPromise): Promise;
export function when(value: T): Promise;
// If a non-promise value is provided, it will not reject or progress
export function when(value: T, onFulfilled: (val: T) => IPromise): Promise;
export function when(value: T, onFulfilled: (val: T) => U): Promise;
export function when(value: IPromise, onFulfilled: (val: T) => IPromise, onRejected?: (reason: any) => IPromise, onProgress?: (progress: any) => any): Promise;
export function when(value: IPromise, onFulfilled: (val: T) => IPromise, onRejected?: (reason: any) => U, onProgress?: (progress: any) => any): Promise;
export function when(value: IPromise, onFulfilled: (val: T) => U, onRejected?: (reason: any) => IPromise, onProgress?: (progress: any) => any): Promise;
export function when(value: IPromise, onFulfilled: (val: T) => U, onRejected?: (reason: any) => U, onProgress?: (progress: any) => any): Promise;
//export function try(method: Function, ...args: any[]): Promise; // <- This is broken currently - not sure how to fix.
export function fbind(method: (...args: any[]) => IPromise, ...args: any[]): (...args: any[]) => Promise;
export function fbind(method: (...args: any[]) => T, ...args: any[]): (...args: any[]) => Promise;
export function fcall(method: (...args: any[]) => T, ...args: any[]): Promise;
export function send(obj: any, functionName: string, ...args: any[]): Promise;
export function invoke(obj: any, functionName: string, ...args: any[]): Promise;
export function mcall(obj: any, functionName: string, ...args: any[]): Promise;
export function nfbind(nodeFunction: Function, ...args: any[]): (...args: any[]) => Promise;
export function nfcall(nodeFunction: Function, ...args: any[]): Promise;
export function ninvoke(nodeModule: any, functionName: string, ...args: any[]): Promise;
export function nsend(nodeModule: any, functionName: string, ...args: any[]): Promise;
export function nmcall(nodeModule: any, functionName: string, ...args: any[]): Promise;
export function all(promises: any[]): Promise;
export function all(promises: IPromise[]): Promise;
export function allSettled(promises: any[]): Promise[]>;
export function allSettled(promises: IPromise[]): Promise[]>;
export function allResolved(promises: any[]): Promise[]>;
export function allResolved(promises: IPromise[]): Promise[]>;
export function spread(promises: any[], onFulfilled: (...args: any[]) => IPromise, onRejected: (reason: any) => IPromise): Promise;
export function spread(promises: any[], onFulfilled: (...args: any[]) => IPromise, onRejected: (reason: any) => U): Promise;
export function spread(promises: any[], onFulfilled: (...args: any[]) => U, onRejected: (reason: any) => IPromise): Promise;
export function spread(promises: any[], onFulfilled: (...args: any[]) => U, onRejected: (reason: any) => U): Promise;
export function spread(promises: IPromise[], onFulfilled: (...args: T[]) => IPromise, onRejected: (reason: any) => IPromise): Promise;
export function spread(promises: IPromise[], onFulfilled: (...args: T[]) => IPromise, onRejected: (reason: any) => U): Promise;
export function spread(promises: IPromise[], onFulfilled: (...args: T[]) => U, onRejected: (reason: any) => IPromise): Promise;
export function spread(promises: IPromise[], onFulfilled: (...args: T[]) => U, onRejected: (reason: any) => U): Promise;
export function timeout(promise: Promise, ms: number, message?: string): Promise;
export function delay(promise: Promise, ms: number): Promise;
export function delay(value: T, ms: number): Promise;
export function isFulfilled(promise: Promise): boolean;
export function isRejected(promise: Promise): boolean;
export function isPending(promise: Promise): boolean;
export function defer(): Deferred;
export function reject(reason?: any): Promise;
export function promise(resolver: (resolve: (val: IPromise) => void , reject: (reason: any) => void , notify: (progress: any) => void ) => void ): Promise;
export function promise(resolver: (resolve: (val: T) => void , reject: (reason: any) => void , notify: (progress: any) => void ) => void ): Promise;
export function promised(callback: (...args: any[]) => T): (...args: any[]) => Promise;
export function isPromise(object: any): boolean;
export function isPromiseAlike(object: any): boolean;
export function isPending(object: any): boolean;
export function async(generatorFunction: any): (...args: any[]) => Promise;
export function nextTick(callback: Function): void;
export var onerror: (reason: any) => void;
export var longStackSupport: boolean;
export function resolve(object: IPromise): Promise;
export function resolve(object: T): Promise;
}
declare module "q" {
export = Q;
}