adding catch onto Thenable, updating tests

This commit is contained in:
Will Johnston
2016-01-15 12:19:16 -06:00
parent 138ad74b9e
commit 5bff5f871a
2 changed files with 31 additions and 27 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> {