Merge pull request #7653 from wjohnsto/master

Adding catch method onto ES6-promise Thenable
This commit is contained in:
Horiuchi_H
2016-01-20 16:57:59 +09:00
3 changed files with 37 additions and 33 deletions
+30 -27
View File
@@ -68,6 +68,9 @@ promiseNumber = thenWithUndefinedFullFillAndPromiseReject;
var thenWithNoResultAndNoReject = promiseString.then<number>();
promiseNumber = thenWithNoResultAndNoReject;
var catchAfterThen = promiseString.then().catch<number>();
promiseNumber = catchAfterThen;
var voidPromise = new Promise<void>(function (resolve) { resolve(); });
//catch test
@@ -161,31 +164,31 @@ getJSON('story.json').then(function(story: Story) {
(<HTMLElement>document.querySelector('.spinner')).style.display = 'none';
});
interface T1 {
__t1: string;
}
interface T2 {
__t2: string;
}
interface T3 {
__t3: string;
}
function f1(): Promise<T1> {
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<T1> {
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" };
});
+1
View File
@@ -6,6 +6,7 @@
interface Thenable<R> {
then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => void): Thenable<U>;
catch<U>(onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
}
declare class Promise<R> implements Thenable<R> {
+6 -6
View File
@@ -4,9 +4,9 @@
/// <reference path="../q/Q.d.ts"/>
/// <reference path="../when/when"/>
var thenNum: PromisesAPlus.Thenable<number>;
var thenStr: PromisesAPlus.Thenable<string>;
var thenBool: PromisesAPlus.Thenable<boolean>;
var thenNum: PromisesAPlus.Thenable<number>;
var thenStr: PromisesAPlus.Thenable<string>;
var thenBool: PromisesAPlus.Thenable<boolean>;
var impl: PromisesAPlus.PromiseImpl;
@@ -45,9 +45,9 @@ function testCompatibleWithRxJS() {
}
function testCompatibleWithES6Promises() {
// from spec to ES6
var es6ThenNum: Thenable<number> = thenNum;
var es6ThenStr: Thenable<string> = thenStr;
// define ES6 thenables
var es6ThenNum: Thenable<number>;
var es6ThenStr: Thenable<string>;
// from ES6 to spec
thenNum = es6ThenNum;