From f8f170dd81835096e774886a353a823711d273e3 Mon Sep 17 00:00:00 2001 From: tarh Date: Sat, 5 Jul 2014 14:23:33 +0100 Subject: [PATCH 1/3] Uniform naming parameters --- es6-promise/es6-promise.d.ts | 202 +++++++++++++++++------------------ 1 file changed, 98 insertions(+), 104 deletions(-) diff --git a/es6-promise/es6-promise.d.ts b/es6-promise/es6-promise.d.ts index 632276822..202d30d29 100644 --- a/es6-promise/es6-promise.d.ts +++ b/es6-promise/es6-promise.d.ts @@ -3,139 +3,133 @@ // Definitions by: François de Campredon // Definitions: https://github.com/borisyankov/DefinitelyTyped - interface Thenable { - then(onFulfilled: (value: R) => Thenable, onRejected: (error: any) => Thenable): Thenable; - then(onFulfilled: (value: R) => Thenable, onRejected?: (error: any) => U): Thenable; - then(onFulfilled: (value: R) => U, onRejected: (error: any) => Thenable): Thenable; - then(onFulfilled?: (value: R) => U, onRejected?: (error: any) => U): Thenable; - + then(onResolve: (value: R) => Thenable, onReject: (error: any) => Thenable): Thenable; + then(onResolve: (value: R) => Thenable, onReject?: (error: any) => U): Thenable; + then(onResolve: (value: R) => U, onReject: (error: any) => Thenable): Thenable; + then(onResolve?: (value: R) => U, onReject?: (error: any) => U): 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(). - */ + /** + * 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); + /** + * 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 : (result: Thenable) => void, reject: (error: any) => void) => void); + + /** + * onResolve is called when/if "promise" resolves. onReject is called when/if "promise" rejects. + * Both are optional, if either/both are omitted the next onResolve/onReject in the chain is called. + * Both callbacks have a single parameter , the fulfillment value or rejection reason. + * "then" returns a new promise equivalent to the value you return from onResolve/onReject after being passed through Promise.resolve. + * If an error is thrown in the callback, the returned promise rejects with that error. + * + * @param onResolve called when/if "promise" resolves + * @param onReject called when/if "promise" rejects + */ + then(onResolve: (value: R) => Thenable, onReject: (error: any) => Thenable): Promise; + /** + * onResolve is called when/if "promise" resolves. onReject is called when/if "promise" rejects. + * Both are optional, if either/both are omitted the next onResolve/onReject in the chain is called. + * Both callbacks have a single parameter , the fulfillment value or rejection reason. + * "then" returns a new promise equivalent to the value you return from onResolve/onReject after being passed through Promise.resolve. + * If an error is thrown in the callback, the returned promise rejects with that error. + * + * @param onResolve called when/if "promise" resolves + * @param onReject called when/if "promise" rejects + */ + then(onResolve: (value: R) => Thenable, onReject?: (error: any) => U): Promise; + /** + * onResolve is called when/if "promise" resolves. onReject is called when/if "promise" rejects. + * Both are optional, if either/both are omitted the next onResolve/onReject in the chain is called. + * Both callbacks have a single parameter , the fulfillment value or rejection reason. + * "then" returns a new promise equivalent to the value you return from onResolve/onReject after being passed through Promise.resolve. + * If an error is thrown in the callback, the returned promise rejects with that error. + * + * @param onResolve called when/if "promise" resolves + * @param onReject called when/if "promise" rejects + */ + then(onResolve: (value: R) => U, onReject: (error: any) => Thenable): Promise; + /** + * onResolve is called when/if "promise" resolves. onReject is called when/if "promise" rejects. + * Both are optional, if either/both are omitted the next onResolve/onReject in the chain is called. + * Both callbacks have a single parameter , the fulfillment value or rejection reason. + * "then" returns a new promise equivalent to the value you return from onResolve/onReject after being passed through Promise.resolve. + * If an error is thrown in the callback, the returned promise rejects with that error. + * + * @param onResolve called when/if "promise" resolves + * @param onReject called when/if "promise" rejects + */ + then(onResolve?: (value: R) => U, onReject?: (error: any) => U): Promise; - - /** - * onFulFill 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 callbacks have a single parameter , the fulfillment value or rejection reason. - * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. - * If an error is thrown in the callback, the returned promise rejects with that error. - * - * @param onFulFill called when/if "promise" resolves - * @param onReject called when/if "promise" rejects - */ - then(onFulfill: (value: R) => Thenable, onReject: (error: any) => Thenable): Promise; - /** - * onFulFill 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 callbacks have a single parameter , the fulfillment value or rejection reason. - * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. - * If an error is thrown in the callback, the returned promise rejects with that error. - * - * @param onFulFill called when/if "promise" resolves - * @param onReject called when/if "promise" rejects - */ - then(onFulfill: (value: R) => Thenable, onReject?: (error: any) => U): Promise; - /** - * onFulFill 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 callbacks have a single parameter , the fulfillment value or rejection reason. - * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. - * If an error is thrown in the callback, the returned promise rejects with that error. - * - * @param onFulFill called when/if "promise" resolves - * @param onReject called when/if "promise" rejects - */ - then(onFulfill: (value: R) => U, onReject: (error: any) => Thenable): Promise; - /** - * onFulFill 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 callbacks have a single parameter , the fulfillment value or rejection reason. - * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. - * If an error is thrown in the callback, the returned promise rejects with that error. - * - * @param onFulFill called when/if "promise" resolves - * @param onReject called when/if "promise" rejects - */ - then(onFulfill?: (value: R) => U, onReject?: (error: any) => U): Promise; - - - /** - * Sugar for promise.then(undefined, onRejected) - * - * @param onReject called when/if "promise" rejects - */ + /** + * Sugar for promise.then(undefined, onReject) + * + * @param onReject called when/if "promise" rejects + */ catch(onReject?: (error: any) => Thenable): Promise; - /** - * Sugar for promise.then(undefined, onRejected) - * - * @param onReject called when/if "promise" rejects - */ + /** + * Sugar for promise.then(undefined, onReject) + * + * @param onReject called when/if "promise" rejects + */ catch(onReject?: (error: any) => U): Promise; } declare module Promise { - /** * Returns promise (only if promise.constructor == Promise) */ function cast(promise: Promise): Promise; - /** + /** * Make a promise that fulfills to obj. */ function 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. - */ + + /** + * 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; - /** - * 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(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; - /** - * 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. - */ + /** + * 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; - /** - * 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(promises: Promise[]): Promise; } declare module 'es6-promise' { - var foo: typeof Promise; // Temp variable to reference Promise in local context - module rsvp { - export var Promise: typeof foo; - } - export = rsvp; + var foo: typeof Promise; // Temp variable to reference Promise in local context + module rsvp { + export var Promise: typeof foo; + } + export = rsvp; } From a685b7db7a80a10d3ffb7575be2e6881d55c0f15 Mon Sep 17 00:00:00 2001 From: tarh Date: Sat, 5 Jul 2014 14:25:56 +0100 Subject: [PATCH 2/3] Works with more use cases --- es6-promise/es6-promise.d.ts | 54 ++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/es6-promise/es6-promise.d.ts b/es6-promise/es6-promise.d.ts index 202d30d29..4e8d27d4d 100644 --- a/es6-promise/es6-promise.d.ts +++ b/es6-promise/es6-promise.d.ts @@ -4,10 +4,12 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped interface Thenable { - then(onResolve: (value: R) => Thenable, onReject: (error: any) => Thenable): Thenable; - then(onResolve: (value: R) => Thenable, onReject?: (error: any) => U): Thenable; - then(onResolve: (value: R) => U, onReject: (error: any) => Thenable): Thenable; + then(onResolve?: (value: R) => Thenable, onReject?: (error: any) => Thenable): Thenable; + then(onResolve?: (value: R) => Thenable, onReject?: (error: any) => U): Thenable; + then(onResolve?: (value: R) => Thenable, onReject?: (error: any) => void): Thenable; + then(onResolve?: (value: R) => U, onReject?: (error: any) => Thenable): Thenable; then(onResolve?: (value: R) => U, onReject?: (error: any) => U): Thenable; + then(onResolve?: (value: R) => U, onReject?: (error: any) => void): Thenable; } declare class Promise implements Thenable { @@ -18,7 +20,7 @@ declare class Promise implements Thenable { * 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); + 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. @@ -26,7 +28,7 @@ declare class Promise implements Thenable { * 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: Thenable) => void, reject: (error: any) => void) => void); + constructor(callback: (resolve : (result?: Thenable) => void, reject: (error: any) => void) => void); /** * onResolve is called when/if "promise" resolves. onReject is called when/if "promise" rejects. @@ -38,7 +40,7 @@ declare class Promise implements Thenable { * @param onResolve called when/if "promise" resolves * @param onReject called when/if "promise" rejects */ - then(onResolve: (value: R) => Thenable, onReject: (error: any) => Thenable): Promise; + then(onResolve?: (value: R) => Thenable, onReject?: (error: any) => Thenable): Promise; /** * onResolve is called when/if "promise" resolves. onReject is called when/if "promise" rejects. * Both are optional, if either/both are omitted the next onResolve/onReject in the chain is called. @@ -49,7 +51,18 @@ declare class Promise implements Thenable { * @param onResolve called when/if "promise" resolves * @param onReject called when/if "promise" rejects */ - then(onResolve: (value: R) => Thenable, onReject?: (error: any) => U): Promise; + then(onResolve?: (value: R) => Thenable, onReject?: (error: any) => U): Promise; + /** + * onResolve is called when/if "promise" resolves. onReject is called when/if "promise" rejects. + * Both are optional, if either/both are omitted the next onResolve/onReject in the chain is called. + * Both callbacks have a single parameter , the fulfillment value or rejection reason. + * "then" returns a new promise equivalent to the value you return from onResolve/onReject after being passed through Promise.resolve. + * If an error is thrown in the callback, the returned promise rejects with that error. + * + * @param onResolve called when/if "promise" resolves + * @param onReject called when/if "promise" rejects + */ + then(onResolve?: (value: R) => Thenable, onReject?: (error: any) => void): Promise; /** * onResolve is called when/if "promise" resolves. onReject is called when/if "promise" rejects. * Both are optional, if either/both are omitted the next onResolve/onReject in the chain is called. @@ -60,7 +73,7 @@ declare class Promise implements Thenable { * @param onResolve called when/if "promise" resolves * @param onReject called when/if "promise" rejects */ - then(onResolve: (value: R) => U, onReject: (error: any) => Thenable): Promise; + then(onResolve?: (value: R) => U, onReject?: (error: any) => Thenable): Promise; /** * onResolve is called when/if "promise" resolves. onReject is called when/if "promise" rejects. * Both are optional, if either/both are omitted the next onResolve/onReject in the chain is called. @@ -72,7 +85,18 @@ declare class Promise implements Thenable { * @param onReject called when/if "promise" rejects */ then(onResolve?: (value: R) => U, onReject?: (error: any) => U): Promise; - + /** + * onResolve is called when/if "promise" resolves. onReject is called when/if "promise" rejects. + * Both are optional, if either/both are omitted the next onResolve/onReject in the chain is called. + * Both callbacks have a single parameter , the fulfillment value or rejection reason. + * "then" returns a new promise equivalent to the value you return from onResolve/onReject after being passed through Promise.resolve. + * If an error is thrown in the callback, the returned promise rejects with that error. + * + * @param onResolve called when/if "promise" resolves + * @param onReject called when/if "promise" rejects + */ + then(onResolve?: (value: R) => U, onReject?: (error: any) => void): Promise; + /** * Sugar for promise.then(undefined, onReject) * @@ -85,6 +109,12 @@ declare class Promise implements Thenable { * @param onReject called when/if "promise" rejects */ catch(onReject?: (error: any) => U): Promise; + /** + * Sugar for promise.then(undefined, onReject) + * + * @param onReject called when/if "promise" rejects + */ + catch(onReject?: (error: any) => void): Promise; } declare module Promise { @@ -95,14 +125,14 @@ declare module Promise { /** * Make a promise that fulfills to obj. */ - function cast(object?: R): Promise; + function 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; + function resolve(thenable?: Thenable): Promise; /** * Make a promise that fulfills to obj. Same as Promise.cast(obj) in this situation. */ @@ -111,7 +141,7 @@ declare module 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; + function reject(error: any): Promise; /** * Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects. From 36a701008e4f9f2e07b3e894936b36f42be5b4cc Mon Sep 17 00:00:00 2001 From: tarh Date: Sun, 6 Jul 2014 08:35:29 +0100 Subject: [PATCH 3/3] Parameter names conform to http://promises-aplus.github.io/promises-spec/ --- es6-promise/es6-promise-tests.ts | 3 + es6-promise/es6-promise.d.ts | 104 +++++++++++++++---------------- 2 files changed, 55 insertions(+), 52 deletions(-) diff --git a/es6-promise/es6-promise-tests.ts b/es6-promise/es6-promise-tests.ts index 549527372..402328eb5 100644 --- a/es6-promise/es6-promise-tests.ts +++ b/es6-promise/es6-promise-tests.ts @@ -74,6 +74,8 @@ promiseNumber = thenWithUndefinedFullFillAndPromiseReject; var thenWithNoResultAndNoReject = promiseString.then(); promiseNumber = thenWithNoResultAndNoReject; +var voidPromise = new Promise(function (resolve) { resolve(); }); + //catch test var catchWithSimpleResult = promiseString.catch(error => 10); promiseNumber = catchWithSimpleResult; @@ -81,6 +83,7 @@ promiseNumber = catchWithSimpleResult; var catchWithPromiseResult = promiseString.catch(error => Promise.resolve(10)); promiseNumber = catchWithPromiseResult; +promiseString = promiseString.catch(function () { throw new Error('Better error msg'); }); //examples coming from http://www.html5rocks.com/en/tutorials/es6/promises/ diff --git a/es6-promise/es6-promise.d.ts b/es6-promise/es6-promise.d.ts index 4e8d27d4d..9bb8d79f2 100644 --- a/es6-promise/es6-promise.d.ts +++ b/es6-promise/es6-promise.d.ts @@ -4,12 +4,12 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped interface Thenable { - then(onResolve?: (value: R) => Thenable, onReject?: (error: any) => Thenable): Thenable; - then(onResolve?: (value: R) => Thenable, onReject?: (error: any) => U): Thenable; - then(onResolve?: (value: R) => Thenable, onReject?: (error: any) => void): Thenable; - then(onResolve?: (value: R) => U, onReject?: (error: any) => Thenable): Thenable; - then(onResolve?: (value: R) => U, onReject?: (error: any) => U): Thenable; - then(onResolve?: (value: R) => U, onReject?: (error: any) => void): Thenable; + then(onFulfilled?: (value: R) => Thenable, onRejected?: (error: any) => Thenable): Thenable; + then(onFulfilled?: (value: R) => Thenable, onRejected?: (error: any) => U): Thenable; + then(onFulfilled?: (value: R) => Thenable, onRejected?: (error: any) => void): Thenable; + then(onFulfilled?: (value: R) => U, onRejected?: (error: any) => Thenable): Thenable; + then(onFulfilled?: (value: R) => U, onRejected?: (error: any) => U): Thenable; + then(onFulfilled?: (value: R) => U, onRejected?: (error: any) => void): Thenable; } declare class Promise implements Thenable { @@ -28,93 +28,93 @@ declare class Promise implements Thenable { * 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?: Thenable) => void, reject: (error: any) => void) => void); + constructor(callback: (resolve : (thenable?: Thenable) => void, reject: (error: any) => void) => void); /** - * onResolve is called when/if "promise" resolves. onReject is called when/if "promise" rejects. - * Both are optional, if either/both are omitted the next onResolve/onReject in the chain is called. + * 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 callbacks have a single parameter , the fulfillment value or rejection reason. - * "then" returns a new promise equivalent to the value you return from onResolve/onReject after being passed through Promise.resolve. + * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. * If an error is thrown in the callback, the returned promise rejects with that error. * - * @param onResolve called when/if "promise" resolves - * @param onReject called when/if "promise" rejects + * @param onFulfilled called when/if "promise" resolves + * @param onRejected called when/if "promise" rejects */ - then(onResolve?: (value: R) => Thenable, onReject?: (error: any) => Thenable): Promise; + then(onFulfilled?: (value: R) => Thenable, onRejected?: (error: any) => Thenable): Promise; /** - * onResolve is called when/if "promise" resolves. onReject is called when/if "promise" rejects. - * Both are optional, if either/both are omitted the next onResolve/onReject in the chain is called. + * 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 callbacks have a single parameter , the fulfillment value or rejection reason. - * "then" returns a new promise equivalent to the value you return from onResolve/onReject after being passed through Promise.resolve. + * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. * If an error is thrown in the callback, the returned promise rejects with that error. * - * @param onResolve called when/if "promise" resolves - * @param onReject called when/if "promise" rejects + * @param onFulfilled called when/if "promise" resolves + * @param onRejected called when/if "promise" rejects */ - then(onResolve?: (value: R) => Thenable, onReject?: (error: any) => U): Promise; + then(onFulfilled?: (value: R) => Thenable, onRejected?: (error: any) => U): Promise; /** - * onResolve is called when/if "promise" resolves. onReject is called when/if "promise" rejects. - * Both are optional, if either/both are omitted the next onResolve/onReject in the chain is called. + * 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 callbacks have a single parameter , the fulfillment value or rejection reason. - * "then" returns a new promise equivalent to the value you return from onResolve/onReject after being passed through Promise.resolve. + * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. * If an error is thrown in the callback, the returned promise rejects with that error. * - * @param onResolve called when/if "promise" resolves - * @param onReject called when/if "promise" rejects + * @param onFulfilled called when/if "promise" resolves + * @param onRejected called when/if "promise" rejects */ - then(onResolve?: (value: R) => Thenable, onReject?: (error: any) => void): Promise; + then(onFulfilled?: (value: R) => Thenable, onRejected?: (error: any) => void): Promise; /** - * onResolve is called when/if "promise" resolves. onReject is called when/if "promise" rejects. - * Both are optional, if either/both are omitted the next onResolve/onReject in the chain is called. + * 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 callbacks have a single parameter , the fulfillment value or rejection reason. - * "then" returns a new promise equivalent to the value you return from onResolve/onReject after being passed through Promise.resolve. + * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. * If an error is thrown in the callback, the returned promise rejects with that error. * - * @param onResolve called when/if "promise" resolves - * @param onReject called when/if "promise" rejects + * @param onFulfilled called when/if "promise" resolves + * @param onRejected called when/if "promise" rejects */ - then(onResolve?: (value: R) => U, onReject?: (error: any) => Thenable): Promise; + then(onFulfilled?: (value: R) => U, onRejected?: (error: any) => Thenable): Promise; /** - * onResolve is called when/if "promise" resolves. onReject is called when/if "promise" rejects. - * Both are optional, if either/both are omitted the next onResolve/onReject in the chain is called. + * 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 callbacks have a single parameter , the fulfillment value or rejection reason. - * "then" returns a new promise equivalent to the value you return from onResolve/onReject after being passed through Promise.resolve. + * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. * If an error is thrown in the callback, the returned promise rejects with that error. * - * @param onResolve called when/if "promise" resolves - * @param onReject called when/if "promise" rejects + * @param onFulfilled called when/if "promise" resolves + * @param onRejected called when/if "promise" rejects */ - then(onResolve?: (value: R) => U, onReject?: (error: any) => U): Promise; + then(onFulfilled?: (value: R) => U, onRejected?: (error: any) => U): Promise; /** - * onResolve is called when/if "promise" resolves. onReject is called when/if "promise" rejects. - * Both are optional, if either/both are omitted the next onResolve/onReject in the chain is called. + * 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 callbacks have a single parameter , the fulfillment value or rejection reason. - * "then" returns a new promise equivalent to the value you return from onResolve/onReject after being passed through Promise.resolve. + * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. * If an error is thrown in the callback, the returned promise rejects with that error. * - * @param onResolve called when/if "promise" resolves - * @param onReject called when/if "promise" rejects + * @param onFulfilled called when/if "promise" resolves + * @param onRejected called when/if "promise" rejects */ - then(onResolve?: (value: R) => U, onReject?: (error: any) => void): Promise; + then(onFulfilled?: (value: R) => U, onRejected?: (error: any) => void): Promise; /** - * Sugar for promise.then(undefined, onReject) + * Sugar for promise.then(undefined, onRejected) * - * @param onReject called when/if "promise" rejects + * @param onRejected called when/if "promise" rejects */ - catch(onReject?: (error: any) => Thenable): Promise; + catch(onRejected?: (error: any) => Thenable): Promise; /** - * Sugar for promise.then(undefined, onReject) + * Sugar for promise.then(undefined, onRejected) * - * @param onReject called when/if "promise" rejects + * @param onRejected called when/if "promise" rejects */ - catch(onReject?: (error: any) => U): Promise; + catch(onRejected?: (error: any) => U): Promise; /** - * Sugar for promise.then(undefined, onReject) + * Sugar for promise.then(undefined, onRejected) * - * @param onReject called when/if "promise" rejects + * @param onRejected called when/if "promise" rejects */ - catch(onReject?: (error: any) => void): Promise; + catch(onRejected?: (error: any) => void): Promise; } declare module Promise {