DefinitelyTyped

Index

Variables

Dynamic modules

Modules

Interfaces

Functions

Variables

$: JQueryStatic

jQuery: JQueryStatic

Functions

Q(promise: IPromise): Promise

If value is a Q promise, returns the promise. If value is a promise from another library it is coerced into a Q promise (where possible).

Parameters

Returns

Promise

Q(promise: JQueryPromise): Promise

If value is a Q promise, returns the promise. If value is a promise from another library it is coerced into a Q promise (where possible).

Parameters

Returns

Promise

Q(value: T): Promise

If value is not a promise, returns a promise that is fulfilled with value.

Parameters

  • value: T

Returns

Promise

longStackSupport: boolean

A settable property that lets you turn on long stack trace support. If turned on, "stack jumps" will be tracked across asynchronous promise operations, so that if an uncaught error is thrown by done or a rejection reason's stack property is inspected in a rejection callback, a long stack trace is produced.

onerror: (reason: any) => void

A settable property that will intercept any uncaught errors that would otherwise be thrown in the next tick of the event loop, usually as a result of done. Can be useful for getting the full stack trace of an error in browsers, which is not usually possible with window.onerror.

Deferred: Deferred

public promise: Promise

public makeNodeResolver(): (reason: any, value: T) => void

Returns

(reason: any, value: T) => void

public notify(value: any)

Parameters

  • value: any

public reject(reason: any)

Parameters

  • reason: any

public resolve(value: T in Q.Deferred<T>)

Parameters

  • value: T in Q.Deferred<T>

IPromise: IPromise

public then(onFulfill: (value: T) => Q.IPromise<U>, onReject?: (reason: any) => Q.IPromise<U>): IPromise

Parameters

  • onFulfill: (value: T) => Q.IPromise<U>
  • onReject?: (reason: any) => Q.IPromise<U> optional

Returns

IPromise

public then(onFulfill: (value: T) => Q.IPromise<U>, onReject?: (reason: any) => U): IPromise

Parameters

  • onFulfill: (value: T) => Q.IPromise<U>
  • onReject?: (reason: any) => U optional

Returns

IPromise

public then(onFulfill: (value: T) => U, onReject?: (reason: any) => Q.IPromise<U>): IPromise

Parameters

  • onFulfill: (value: T) => U
  • onReject?: (reason: any) => Q.IPromise<U> optional

Returns

IPromise

public then(onFulfill: (value: T) => U, onReject?: (reason: any) => U): IPromise

Parameters

  • onFulfill: (value: T) => U
  • onReject?: (reason: any) => U optional

Returns

IPromise

Promise: Promise

public catch(onRejected: (reason: any) => U): Promise

A sugar method, equivalent to promise.then(undefined, onRejected).

Parameters

  • onRejected: (reason: any) => U

Returns

Promise

public catch(onRejected: (reason: any) => Q.IPromise<U>): Promise

A sugar method, equivalent to promise.then(undefined, onRejected).

Parameters

  • onRejected: (reason: any) => Q.IPromise<U>

Returns

Promise

public delay(ms: number): Promise

Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed.

Parameters

  • ms: number

Returns

Promise

public delete(propertyName: String): Promise

Parameters

  • propertyName: String

Returns

Promise

public done(onFulfilled?: (value: T) => any, onRejected?: (reason: any) => any, onProgress?: (progress: any) => any)

Much like then, but with different behavior around unhandled rejection. If there is an unhandled rejection, either because promise is rejected and no onRejected callback was provided, or because onFulfilled or onRejected threw an error or returned a rejected promise, the resulting rejection reason is thrown as an exception in a future turn of the event loop.

This method should be used to terminate chains of promises that will not be passed elsewhere. Since exceptions thrown in then callbacks are consumed and transformed into rejections, exceptions at the end of the chain are easy to accidentally, silently ignore. By arranging for the exception to be thrown in a future turn of the event loop, so that it won't be caught, it causes an onerror event on the browser window, or an uncaughtException event on Node.js's process object.

Exceptions thrown by done will have long stack traces, if Q.longStackSupport is set to true. If Q.onerror is set, exceptions will be delivered there instead of thrown in a future turn.

The Golden Rule of done vs. then usage is: either return your promise to someone else, or if the chain ends with you, call done to terminate it.

Parameters

  • onFulfilled?: (value: T) => any optional
  • onRejected?: (reason: any) => any optional
  • onProgress?: (progress: any) => any optional

public fail(onRejected: (reason: any) => U): Promise

Parameters

  • onRejected: (reason: any) => U

Returns

Promise

public fail(onRejected: (reason: any) => Q.IPromise<U>): Promise

Parameters

  • onRejected: (reason: any) => Q.IPromise<U>

Returns

Promise

public fapply(args: Array<any>): Promise

Parameters

  • args: Array<any>

Returns

Promise

public fcall(args?: Array<any>): Promise

Parameters

  • args?: Array<any> optional

Returns

Promise

public fin(finallyCallback: () => any): Promise

Like a finally clause, allows you to observe either the fulfillment or rejection of a promise, but to do so without modifying the final value. This is useful for collecting resources regardless of whether a job succeeded, like closing a database connection, shutting a server down, or deleting an unneeded key from an object.

finally returns a promise, which will become resolved with the same fulfillment value or rejection reason as promise. However, if callback returns a promise, the resolution of the returned promise will be delayed until the promise returned from callback is finished.

Parameters

  • finallyCallback: () => any

Returns

Promise

public finally(finallyCallback: () => any): Promise

Like a finally clause, allows you to observe either the fulfillment or rejection of a promise, but to do so without modifying the final value. This is useful for collecting resources regardless of whether a job succeeded, like closing a database connection, shutting a server down, or deleting an unneeded key from an object.

finally returns a promise, which will become resolved with the same fulfillment value or rejection reason as promise. However, if callback returns a promise, the resolution of the returned promise will be delayed until the promise returned from callback is finished.

Parameters

  • finallyCallback: () => any

Returns

Promise

public get(propertyName: String): Promise

Returns a promise to get the named property of an object. Essentially equivalent to

promise.then(function (o) { return o[propertyName]; });

Parameters

  • propertyName: String

Returns

Promise

public inspect(): PromiseState

Returns a "state snapshot" object, which will be in one of three forms:

  • { state: "pending" }
  • { state: "fulfilled", value: }
  • { state: "rejected", reason: }

Returns

PromiseState

public invoke(methodName: String, args?: Array<any>): Promise

Returns a promise for the result of calling the named method of an object with the given variadic arguments. The object itself is this in the function, just like a synchronous method call.

Parameters

  • methodName: String
  • args?: Array<any> optional

Returns

Promise

public isFulfilled(): boolean

Returns whether a given promise is in the fulfilled state. When the static version is used on non-promises, the result is always true.

Returns

boolean

public isPending(): boolean

Returns whether a given promise is in the pending state. When the static version is used on non-promises, the result is always false.

Returns

boolean

public isRejected(): boolean

Returns whether a given promise is in the rejected state. When the static version is used on non-promises, the result is always false.

Returns

boolean

public keys(): Promise

Returns a promise for an array of the property names of an object. Essentially equivalent to

promise.then(function (o) { return Object.keys(o); });

Returns

Promise

public post(methodName: String, args: Array<any>): Promise

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); });

Parameters

  • methodName: String
  • args: Array<any>

Returns

Promise

public progress(onProgress: (progress: any) => any): Promise

A sugar method, equivalent to promise.then(undefined, undefined, onProgress).

Parameters

  • onProgress: (progress: any) => any

Returns

Promise

public set(propertyName: String, value: any): Promise

Parameters

  • propertyName: String
  • value: any

Returns

Promise

public spread(onFulfilled: Function, onRejected?: Function): Promise

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

Parameters

  • onFulfilled: Function
  • onRejected?: Function optional

Returns

Promise

public then(onFulfill: (value: T) => Q.IPromise<U>, onReject?: (reason: any) => Q.IPromise<U>, onProgress?: Function): Promise

The then method from the Promises/A+ specification, with an additional progress handler.

Parameters

  • onFulfill: (value: T) => Q.IPromise<U>
  • onReject?: (reason: any) => Q.IPromise<U> optional
  • onProgress?: Function optional

Returns

Promise

public then(onFulfill: (value: T) => Q.IPromise<U>, onReject?: (reason: any) => U, onProgress?: Function): Promise

The then method from the Promises/A+ specification, with an additional progress handler.

Parameters

  • onFulfill: (value: T) => Q.IPromise<U>
  • onReject?: (reason: any) => U optional
  • onProgress?: Function optional

Returns

Promise

public then(onFulfill: (value: T) => U, onReject?: (reason: any) => Q.IPromise<U>, onProgress?: Function): Promise

The then method from the Promises/A+ specification, with an additional progress handler.

Parameters

  • onFulfill: (value: T) => U
  • onReject?: (reason: any) => Q.IPromise<U> optional
  • onProgress?: Function optional

Returns

Promise

public then(onFulfill: (value: T) => U, onReject?: (reason: any) => U, onProgress?: Function): Promise

The then method from the Promises/A+ specification, with an additional progress handler.

Parameters

  • onFulfill: (value: T) => U
  • onReject?: (reason: any) => U optional
  • onProgress?: Function optional

Returns

Promise

public thenReject(reason: any): Promise

A sugar method, equivalent to promise.then(function () { throw reason; }).

Parameters

  • reason: any

Returns

Promise

public thenResolve(value: U): Promise

A sugar method, equivalent to promise.then(function () { return value; }).

Parameters

  • value: U

Returns

Promise

public timeout(ms: number, message?: string): Promise

Parameters

  • ms: number
  • message?: string optional

Returns

Promise

public valueOf(): any

Returns

any

PromiseState: PromiseState

optional public reason?: any

public state: string

"fulfilled", "rejected", "pending"

optional public value?: T in Q.PromiseState<T>

all(promises: IPromise[]): Promise

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.

Parameters

Returns

Promise

all(promises: Array<any>): Promise

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.

Parameters

  • promises: Array<any>

Returns

Promise

allResolved(promises: IPromise[]): Promise

Parameters

Returns

Promise

allResolved(promises: Array<any>): Promise

Parameters

  • promises: Array<any>

Returns

Promise

allSettled(promises: IPromise[]): Promise

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.

Parameters

Returns

Promise

allSettled(promises: Array<any>): Promise

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.

Parameters

  • promises: Array<any>

Returns

Promise

async(generatorFunction: any): (...args: any[]) => Q.Promise<T>

This is an experimental tool for converting a generator function into a deferred function. This has the potential of reducing nested callbacks in engines that support yield.

Parameters

  • generatorFunction: any

Returns

(...args: any[]) => Q.Promise<T>

defer(): Deferred

Returns a "deferred" object with a: promise property resolve(value) method reject(reason) method notify(value) method makeNodeResolver() method

Returns

Deferred

delay(promise: Promise, ms: number): Promise

Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed.

Parameters

Returns

Promise

delay(value: T, ms: number): Promise

Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed.

Parameters

  • value: T
  • ms: number

Returns

Promise

denodeify(nodeFunction: Function, args?: Array<any>): (...args: any[]) => Q.Promise<T>

Parameters

  • nodeFunction: Function
  • args?: Array<any> optional

Returns

(...args: any[]) => Q.Promise<T>

fbind(method: (...args: any[]) => Q.IPromise<T>, args?: Array<any>): (...args: any[]) => Q.Promise<T>

Parameters

  • method: (...args: any[]) => Q.IPromise<T>
  • args?: Array<any> optional

Returns

(...args: any[]) => Q.Promise<T>

fbind(method: (...args: any[]) => T, args?: Array<any>): (...args: any[]) => Q.Promise<T>

Parameters

  • method: (...args: any[]) => T
  • args?: Array<any> optional

Returns

(...args: any[]) => Q.Promise<T>

fcall(method: (...args: any[]) => T, args?: Array<any>): Promise

Parameters

  • method: (...args: any[]) => T
  • args?: Array<any> optional

Returns

Promise

invoke(obj: any, functionName: string, args?: Array<any>): Promise

Parameters

  • obj: any
  • functionName: string
  • args?: Array<any> optional

Returns

Promise

isFulfilled(promise: Promise): boolean

Returns whether a given promise is in the fulfilled state. When the static version is used on non-promises, the result is always true.

Parameters

Returns

boolean

isPending(promise: Promise): boolean

Returns whether a given promise is in the pending state. When the static version is used on non-promises, the result is always false.

Parameters

Returns

boolean

isPending(object: any): boolean

Returns whether a given promise is in the pending state. When the static version is used on non-promises, the result is always false.

Parameters

  • object: any

Returns

boolean

isPromise(object: any): boolean

Returns whether the given value is a Q promise.

Parameters

  • object: any

Returns

boolean

isPromiseAlike(object: any): boolean

Returns whether the given value is a promise (i.e. it's an object with a then function).

Parameters

  • object: any

Returns

boolean

isRejected(promise: Promise): boolean

Returns whether a given promise is in the rejected state. When the static version is used on non-promises, the result is always false.

Parameters

Returns

boolean

mcall(obj: any, functionName: string, args?: Array<any>): Promise

Parameters

  • obj: any
  • functionName: string
  • args?: Array<any> optional

Returns

Promise

nbind(nodeFunction: Function, thisArg: any, args?: Array<any>): (...args: any[]) => Q.Promise<T>

Parameters

  • nodeFunction: Function
  • thisArg: any
  • args?: Array<any> optional

Returns

(...args: any[]) => Q.Promise<T>

nextTick(callback: Function)

Parameters

  • callback: Function

nfapply(nodeFunction: Function, args: Array<any>): Promise

Parameters

  • nodeFunction: Function
  • args: Array<any>

Returns

Promise

nfbind(nodeFunction: Function, args?: Array<any>): (...args: any[]) => Q.Promise<T>

Parameters

  • nodeFunction: Function
  • args?: Array<any> optional

Returns

(...args: any[]) => Q.Promise<T>

nfcall(nodeFunction: Function, args?: Array<any>): Promise

Parameters

  • nodeFunction: Function
  • args?: Array<any> optional

Returns

Promise

ninvoke(nodeModule: any, functionName: string, args?: Array<any>): Promise

Parameters

  • nodeModule: any
  • functionName: string
  • args?: Array<any> optional

Returns

Promise

nmcall(nodeModule: any, functionName: string, args?: Array<any>): Promise

Parameters

  • nodeModule: any
  • functionName: string
  • args?: Array<any> optional

Returns

Promise

nsend(nodeModule: any, functionName: string, args?: Array<any>): Promise

Parameters

  • nodeModule: any
  • functionName: string
  • args?: Array<any> optional

Returns

Promise

promise(resolver: (resolve: (val: Q.IPromise<T>) => void, reject: (reason: any) => void, notify: (progress: any) => void) => void): Promise

Parameters

  • resolver: (resolve: (val: Q.IPromise<T>) => void, reject: (reason: any) => void, notify: (progress: any) => void) => void

Returns

Promise

promise(resolver: (resolve: (val: T) => void, reject: (reason: any) => void, notify: (progress: any) => void) => void): Promise

Parameters

  • resolver: (resolve: (val: T) => void, reject: (reason: any) => void, notify: (progress: any) => void) => void

Returns

Promise

promised(callback: (...args: any[]) => T): (...args: any[]) => Q.Promise<T>

Creates a new version of func that accepts any combination of promise and non-promise values, converting them to their fulfillment values before calling the original func. The returned version also always returns a promise: if func does a return or throw, then Q.promised(func) will return fulfilled or rejected promise, respectively.

This can be useful for creating functions that accept either promises or non-promise values, and for ensuring that the function always returns a promise even in the face of unintentional thrown exceptions.

Parameters

  • callback: (...args: any[]) => T

Returns

(...args: any[]) => Q.Promise<T>

reject(reason?: any): Promise

Returns a promise that is rejected with reason.

Parameters

  • reason?: any optional

Returns

Promise

resolve(object: IPromise): Promise

Calling resolve with a pending promise causes promise to wait on the passed promise, becoming fulfilled with its fulfillment value or rejected with its rejection reason (or staying pending forever, if the passed promise does). Calling resolve with a rejected promise causes promise to be rejected with the passed promise's rejection reason. Calling resolve with a fulfilled promise causes promise to be fulfilled with the passed promise's fulfillment value. Calling resolve with a non-promise value causes promise to be fulfilled with that value.

Parameters

Returns

Promise

resolve(object: T): Promise

Calling resolve with a pending promise causes promise to wait on the passed promise, becoming fulfilled with its fulfillment value or rejected with its rejection reason (or staying pending forever, if the passed promise does). Calling resolve with a rejected promise causes promise to be rejected with the passed promise's rejection reason. Calling resolve with a fulfilled promise causes promise to be fulfilled with the passed promise's fulfillment value. Calling resolve with a non-promise value causes promise to be fulfilled with that value.

Parameters

  • object: T

Returns

Promise

send(obj: any, functionName: string, args?: Array<any>): Promise

Parameters

  • obj: any
  • functionName: string
  • args?: Array<any> optional

Returns

Promise

spread(promises: Array<any>, onFulfilled: (...args: any[]) => Q.IPromise<U>, onRejected: (reason: any) => Q.IPromise<U>): Promise

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.

Parameters

  • promises: Array<any>
  • onFulfilled: (...args: any[]) => Q.IPromise<U>
  • onRejected: (reason: any) => Q.IPromise<U>

Returns

Promise

spread(promises: Array<any>, onFulfilled: (...args: any[]) => Q.IPromise<U>, onRejected: (reason: any) => U): Promise

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.

Parameters

  • promises: Array<any>
  • onFulfilled: (...args: any[]) => Q.IPromise<U>
  • onRejected: (reason: any) => U

Returns

Promise

spread(promises: Array<any>, onFulfilled: (...args: any[]) => U, onRejected: (reason: any) => Q.IPromise<U>): Promise

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.

Parameters

  • promises: Array<any>
  • onFulfilled: (...args: any[]) => U
  • onRejected: (reason: any) => Q.IPromise<U>

Returns

Promise

spread(promises: Array<any>, onFulfilled: (...args: any[]) => U, onRejected: (reason: any) => U): Promise

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.

Parameters

  • promises: Array<any>
  • onFulfilled: (...args: any[]) => U
  • onRejected: (reason: any) => U

Returns

Promise

spread(promises: IPromise[], onFulfilled: (...args: T[]) => Q.IPromise<U>, onRejected: (reason: any) => Q.IPromise<U>): Promise

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.

Parameters

  • promises: IPromise[]
  • onFulfilled: (...args: T[]) => Q.IPromise<U>
  • onRejected: (reason: any) => Q.IPromise<U>

Returns

Promise

spread(promises: IPromise[], onFulfilled: (...args: T[]) => Q.IPromise<U>, onRejected: (reason: any) => U): Promise

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.

Parameters

  • promises: IPromise[]
  • onFulfilled: (...args: T[]) => Q.IPromise<U>
  • onRejected: (reason: any) => U

Returns

Promise

spread(promises: IPromise[], onFulfilled: (...args: T[]) => U, onRejected: (reason: any) => Q.IPromise<U>): Promise

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.

Parameters

  • promises: IPromise[]
  • onFulfilled: (...args: T[]) => U
  • onRejected: (reason: any) => Q.IPromise<U>

Returns

Promise

spread(promises: IPromise[], onFulfilled: (...args: T[]) => U, onRejected: (reason: any) => U): Promise

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.

Parameters

  • promises: IPromise[]
  • onFulfilled: (...args: T[]) => U
  • onRejected: (reason: any) => U

Returns

Promise

timeout(promise: Promise, ms: number, message?: string): Promise

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".

Parameters

  • promise: Promise
  • ms: number
  • message?: string optional

Returns

Promise

when(value: IPromise): Promise

Parameters

Returns

Promise

when(value: T): Promise

Parameters

  • value: T

Returns

Promise

when(value: T, onFulfilled: (val: T) => Q.IPromise<U>): Promise

Parameters

  • value: T
  • onFulfilled: (val: T) => Q.IPromise<U>

Returns

Promise

when(value: T, onFulfilled: (val: T) => U): Promise

Parameters

  • value: T
  • onFulfilled: (val: T) => U

Returns

Promise

when(value: IPromise, onFulfilled: (val: T) => Q.IPromise<U>, onRejected?: (reason: any) => Q.IPromise<U>, onProgress?: (progress: any) => any): Promise

Parameters

  • value: IPromise
  • onFulfilled: (val: T) => Q.IPromise<U>
  • onRejected?: (reason: any) => Q.IPromise<U> optional
  • onProgress?: (progress: any) => any optional

Returns

Promise

when(value: IPromise, onFulfilled: (val: T) => Q.IPromise<U>, onRejected?: (reason: any) => U, onProgress?: (progress: any) => any): Promise

Parameters

  • value: IPromise
  • onFulfilled: (val: T) => Q.IPromise<U>
  • onRejected?: (reason: any) => U optional
  • onProgress?: (progress: any) => any optional

Returns

Promise

when(value: IPromise, onFulfilled: (val: T) => U, onRejected?: (reason: any) => Q.IPromise<U>, onProgress?: (progress: any) => any): Promise

Parameters

  • value: IPromise
  • onFulfilled: (val: T) => U
  • onRejected?: (reason: any) => Q.IPromise<U> optional
  • onProgress?: (progress: any) => any optional

Returns

Promise

when(value: IPromise, onFulfilled: (val: T) => U, onRejected?: (reason: any) => U, onProgress?: (progress: any) => any): Promise

Parameters

  • value: IPromise
  • onFulfilled: (val: T) => U
  • onRejected?: (reason: any) => U optional
  • onProgress?: (progress: any) => any optional

Returns

Promise