From 5bff5f871a0ea58be885fb52146cb67b86bcc1ae Mon Sep 17 00:00:00 2001 From: Will Johnston Date: Fri, 15 Jan 2016 12:19:16 -0600 Subject: [PATCH 1/2] adding catch onto Thenable, updating tests --- es6-promise/es6-promise-tests.ts | 57 +++++++++++++++++--------------- es6-promise/es6-promise.d.ts | 1 + 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/es6-promise/es6-promise-tests.ts b/es6-promise/es6-promise-tests.ts index 0980ac26c..ac4f92d3d 100644 --- a/es6-promise/es6-promise-tests.ts +++ b/es6-promise/es6-promise-tests.ts @@ -68,6 +68,9 @@ promiseNumber = thenWithUndefinedFullFillAndPromiseReject; var thenWithNoResultAndNoReject = promiseString.then(); promiseNumber = thenWithNoResultAndNoReject; +var catchAfterThen = promiseString.then().catch(); +promiseNumber = catchAfterThen; + var voidPromise = new Promise(function (resolve) { resolve(); }); //catch test @@ -161,31 +164,31 @@ getJSON('story.json').then(function(story: Story) { (document.querySelector('.spinner')).style.display = 'none'; }); -interface T1 { - __t1: string; -} - -interface T2 { - __t2: string; -} - -interface T3 { - __t3: string; -} - -function f1(): Promise { - return Promise.resolve({ __t1: "foo_t1" }); -} - -function f2(x: T1): T2 { - return { __t2: x.__t1 + ":foo_21" }; -} - -var x3 = f1() - .then(f2, (e: Error) => { - console.log("error 1"); - throw e; -}) - .then((x: T2) => { - return { __t3: x.__t2 + "bar" }; +interface T1 { + __t1: string; +} + +interface T2 { + __t2: string; +} + +interface T3 { + __t3: string; +} + +function f1(): Promise { + return Promise.resolve({ __t1: "foo_t1" }); +} + +function f2(x: T1): T2 { + return { __t2: x.__t1 + ":foo_21" }; +} + +var x3 = f1() + .then(f2, (e: Error) => { + console.log("error 1"); + throw e; +}) + .then((x: T2) => { + return { __t3: x.__t2 + "bar" }; }); \ No newline at end of file diff --git a/es6-promise/es6-promise.d.ts b/es6-promise/es6-promise.d.ts index daf7134f7..a8f8d7845 100644 --- a/es6-promise/es6-promise.d.ts +++ b/es6-promise/es6-promise.d.ts @@ -6,6 +6,7 @@ interface Thenable { then(onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => U | Thenable): Thenable; then(onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => void): Thenable; + catch(onRejected?: (error: any) => U | Thenable): Thenable; } declare class Promise implements Thenable { From 0224e96881ac7a7ee8017defbe397ff5d8c77c15 Mon Sep 17 00:00:00 2001 From: Will Johnston Date: Fri, 15 Jan 2016 12:25:22 -0600 Subject: [PATCH 2/2] fixing promises a plus test for compatibility with es6 promises --- promises-a-plus/promises-a-plus-tests.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/promises-a-plus/promises-a-plus-tests.ts b/promises-a-plus/promises-a-plus-tests.ts index bf6cc5ce0..0d7f5261a 100644 --- a/promises-a-plus/promises-a-plus-tests.ts +++ b/promises-a-plus/promises-a-plus-tests.ts @@ -4,9 +4,9 @@ /// /// -var thenNum: PromisesAPlus.Thenable; -var thenStr: PromisesAPlus.Thenable; -var thenBool: PromisesAPlus.Thenable; +var thenNum: PromisesAPlus.Thenable; +var thenStr: PromisesAPlus.Thenable; +var thenBool: PromisesAPlus.Thenable; var impl: PromisesAPlus.PromiseImpl; @@ -45,9 +45,9 @@ function testCompatibleWithRxJS() { } function testCompatibleWithES6Promises() { - // from spec to ES6 - var es6ThenNum: Thenable = thenNum; - var es6ThenStr: Thenable = thenStr; + // define ES6 thenables + var es6ThenNum: Thenable; + var es6ThenStr: Thenable; // from ES6 to spec thenNum = es6ThenNum;