mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #7653 from wjohnsto/master
Adding catch method onto ES6-promise Thenable
This commit is contained in:
@@ -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" };
|
||||
});
|
||||
Vendored
+1
@@ -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> {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user