mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
Merge pull request #1134 from NativeScript/hdeshev/es6-promise-update
Unify the Promise definition with the one in es6-shim.
This commit is contained in:
50
es6-promise.d.ts
vendored
50
es6-promise.d.ts
vendored
@ -12,24 +12,7 @@ interface Thenable<R> {
|
|||||||
then<U>(onFulfilled?: (value: R) => U, onRejected?: (error: any) => void): Thenable<U>;
|
then<U>(onFulfilled?: (value: R) => U, onRejected?: (error: any) => void): Thenable<U>;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare class Promise<R> implements Thenable<R> {
|
interface Promise<R> extends Thenable<R> {
|
||||||
/**
|
|
||||||
* 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<R>) => void, reject: (error: any) => void) => void);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onFulfilled is called when/if "promise" resolves. onRejected is called when/if "promise" rejects.
|
* 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.
|
* Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called.
|
||||||
@ -108,41 +91,56 @@ declare class Promise<R> implements Thenable<R> {
|
|||||||
catch<U>(onRejected?: (error: any) => void): Promise<U>;
|
catch<U>(onRejected?: (error: any) => void): Promise<U>;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module Promise {
|
interface PromiseConstructor {
|
||||||
|
/**
|
||||||
|
* A reference to the prototype.
|
||||||
|
*/
|
||||||
|
prototype: Promise<any>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 <T>(executor: (resolve: (value?: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns promise (only if promise.constructor == Promise)
|
* Returns promise (only if promise.constructor == Promise)
|
||||||
*/
|
*/
|
||||||
function cast<R>(promise: Promise<R>): Promise<R>;
|
cast<R>(promise: Promise<R>): Promise<R>;
|
||||||
/**
|
/**
|
||||||
* Make a promise that fulfills to obj.
|
* Make a promise that fulfills to obj.
|
||||||
*/
|
*/
|
||||||
function cast<R>(object: R): Promise<R>;
|
cast<R>(object: R): Promise<R>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a new promise from the thenable.
|
* Make a new promise from the thenable.
|
||||||
* A thenable is promise-like in as far as it has a "then" method.
|
* 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.
|
* 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<R>(thenable?: Thenable<R>): Promise<R>;
|
resolve<R>(thenable?: Thenable<R>): Promise<R>;
|
||||||
/**
|
/**
|
||||||
* Make a promise that fulfills to obj. Same as Promise.cast(obj) in this situation.
|
* Make a promise that fulfills to obj. Same as Promise.cast(obj) in this situation.
|
||||||
*/
|
*/
|
||||||
function resolve<R>(object?: R): Promise<R>;
|
resolve<R>(object?: R): Promise<R>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a promise that rejects to obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error
|
* 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<any>;
|
reject(error: any): Promise<any>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects.
|
* 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 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.
|
* The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value.
|
||||||
*/
|
*/
|
||||||
function all<R>(promises: Promise<R>[]): Promise<R[]>;
|
all<R>(promises: Promise<R>[]): Promise<R[]>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a Promise that fulfills when any item fulfills, and rejects if any item rejects.
|
* Make a Promise that fulfills when any item fulfills, and rejects if any item rejects.
|
||||||
*/
|
*/
|
||||||
function race<R>(promises: Promise<R>[]): Promise<R>;
|
race<R>(promises: Promise<R>[]): Promise<R>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare var Promise: PromiseConstructor;
|
||||||
|
Reference in New Issue
Block a user