Skip to content

Commit 2bb2d33

Browse files
committed
Merge pull request DefinitelyTyped#4280 from JsonFreeman/master
Fix ES6 Promise typings so that a void error callback does not mess up inference
2 parents 6fb56c5 + 35119c8 commit 2bb2d33

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

es6-promise/es6-promise-tests.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,32 @@ getJSON('story.json').then(function(story: Story) {
160160
}).then(function() {
161161
(<HTMLElement>document.querySelector('.spinner')).style.display = 'none';
162162
});
163+
164+
interface T1 {
165+
__t1: string;
166+
}
167+
168+
interface T2 {
169+
__t2: string;
170+
}
171+
172+
interface T3 {
173+
__t3: string;
174+
}
175+
176+
function f1(): Promise<T1> {
177+
return Promise.resolve({ __t1: "foo_t1" });
178+
}
179+
180+
function f2(x: T1): T2 {
181+
return { __t2: x.__t1 + ":foo_21" };
182+
}
183+
184+
var x3 = f1()
185+
.then(f2, (e: Error) => {
186+
console.log("error 1");
187+
throw e;
188+
})
189+
.then((x: T2) => {
190+
return { __t3: x.__t2 + "bar" };
191+
});

es6-promise/es6-promise.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
// Definitions: https://github.com/borisyankov/DefinitelyTyped
55

66
interface Thenable<R> {
7-
then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
7+
then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
8+
then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => void): Thenable<U>;
89
}
910

1011
declare class Promise<R> implements Thenable<R> {
@@ -27,7 +28,8 @@ declare class Promise<R> implements Thenable<R> {
2728
* @param onFulfilled called when/if "promise" resolves
2829
* @param onRejected called when/if "promise" rejects
2930
*/
30-
then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Promise<U>;
31+
then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Promise<U>;
32+
then<U>(onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => void): Promise<U>;
3133

3234
/**
3335
* Sugar for promise.then(undefined, onRejected)

0 commit comments

Comments
 (0)