diff --git a/es6-promise.d.ts b/es6-promise.d.ts index b8f93387b..c6830fddb 100644 --- a/es6-promise.d.ts +++ b/es6-promise.d.ts @@ -12,24 +12,7 @@ interface Thenable { then(onFulfilled?: (value: R) => U, onRejected?: (error: any) => void): Thenable; } -declare class Promise implements Thenable { - /** - * If you call resolve in the body of the callback passed to the constructor, - * your promise is fulfilled with result object passed to resolve. - * If you call reject your promise is rejected with the object passed to resolve. - * For consistency and debugging (eg stack traces), obj should be an instanceof Error. - * Any errors thrown in the constructor callback will be implicitly passed to reject(). - */ - constructor(callback: (resolve: (result?: R) => void, reject: (error: any) => void) => void); - /** - * If you call resolve in the body of the callback passed to the constructor, - * your promise will be fulfilled/rejected with the outcome of thenable passed to resolve. - * If you call reject your promise is rejected with the object passed to resolve. - * For consistency and debugging (eg stack traces), obj should be an instanceof Error. - * Any errors thrown in the constructor callback will be implicitly passed to reject(). - */ - constructor(callback: (resolve: (thenable?: Thenable) => void, reject: (error: any) => void) => void); - +interface Promise extends Thenable { /** * onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects. * Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called. @@ -108,41 +91,56 @@ declare class Promise implements Thenable { catch(onRejected?: (error: any) => void): Promise; } -declare module Promise { +interface PromiseConstructor { + /** + * A reference to the prototype. + */ + prototype: Promise; + + /** + * Creates a new Promise. + * @param executor A callback used to initialize the promise. This callback is passed two arguments: + * a resolve callback used resolve the promise with a value or the result of another promise, + * and a reject callback used to reject the promise with a provided reason or error. + */ + new (executor: (resolve: (value?: T | PromiseLike) => void, reject: (reason?: any) => void) => void): Promise; + /** * Returns promise (only if promise.constructor == Promise) */ - function cast(promise: Promise): Promise; + cast(promise: Promise): Promise; /** * Make a promise that fulfills to obj. */ - function cast(object: R): Promise; + cast(object: R): Promise; /** * Make a new promise from the thenable. * A thenable is promise-like in as far as it has a "then" method. * This also creates a new promise if you pass it a genuine JavaScript promise, making it less efficient for casting than Promise.cast. */ - function resolve(thenable?: Thenable): Promise; + resolve(thenable?: Thenable): Promise; /** * Make a promise that fulfills to obj. Same as Promise.cast(obj) in this situation. */ - function resolve(object?: R): Promise; + resolve(object?: R): Promise; /** * Make a promise that rejects to obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error */ - function reject(error: any): Promise; + reject(error: any): Promise; /** * Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects. * the array passed to all can be a mixture of promise-like objects and other objects. * The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value. */ - function all(promises: Promise[]): Promise; + all(promises: Promise[]): Promise; /** * Make a Promise that fulfills when any item fulfills, and rejects if any item rejects. */ - function race(promises: Promise[]): Promise; + race(promises: Promise[]): Promise; } + +declare var Promise: PromiseConstructor;