Skip to content

Commit 9d4219a

Browse files
committed
Adjust overloads to fix #10524.
1 parent ab2750a commit 9d4219a

16 files changed

+614
-609
lines changed

src/lib/es2015.promise.d.ts

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,29 @@
22
* Represents the completion of an asynchronous operation
33
*/
44
interface Promise<T> {
5-
/**
6-
* Creates a new Promise with the same internal state of this Promise.
7-
* @returns A Promise.
8-
*/
9-
then(): Promise<T>;
10-
11-
/**
12-
* Attaches callbacks for the resolution and/or rejection of the Promise.
13-
* @param onfulfilled The callback to execute when the Promise is resolved.
14-
* @returns A Promise for the completion of which ever callback is executed.
15-
*/
16-
then(onfulfilled: undefined | null): Promise<T>;
17-
18-
/**
19-
* Attaches callbacks for the resolution and/or rejection of the Promise.
20-
* @param onfulfilled The callback to execute when the Promise is resolved.
21-
* @returns A Promise for the completion of which ever callback is executed.
22-
*/
23-
then<TResult>(onfulfilled: (value: T) => TResult | PromiseLike<TResult>): Promise<TResult>;
24-
255
/**
266
* Attaches callbacks for the resolution and/or rejection of the Promise.
277
* @param onfulfilled The callback to execute when the Promise is resolved.
288
* @param onrejected The callback to execute when the Promise is rejected.
299
* @returns A Promise for the completion of which ever callback is executed.
3010
*/
31-
then(onfulfilled: undefined | null, onrejected: undefined | null): Promise<T>;
11+
then(onfulfilled?: ((value: T) => T | PromiseLike<T>) | undefined | null, onrejected?: ((reason: any) => T | PromiseLike<T>) | undefined | null): Promise<T>;
3212

3313
/**
3414
* Attaches callbacks for the resolution and/or rejection of the Promise.
3515
* @param onfulfilled The callback to execute when the Promise is resolved.
3616
* @param onrejected The callback to execute when the Promise is rejected.
3717
* @returns A Promise for the completion of which ever callback is executed.
3818
*/
39-
then<TResult>(onfulfilled: undefined | null, onrejected: (reason: any) => TResult | PromiseLike<TResult>): Promise<T | TResult>;
19+
then<TResult>(onfulfilled: ((value: T) => T | PromiseLike<T>) | undefined | null, onrejected: (reason: any) => TResult | PromiseLike<TResult>): Promise<T | TResult>;
4020

4121
/**
4222
* Attaches callbacks for the resolution and/or rejection of the Promise.
4323
* @param onfulfilled The callback to execute when the Promise is resolved.
4424
* @param onrejected The callback to execute when the Promise is rejected.
4525
* @returns A Promise for the completion of which ever callback is executed.
4626
*/
47-
then<TResult>(onfulfilled: (value: T) => TResult | PromiseLike<TResult>, onrejected: undefined | null): Promise<TResult>;
27+
then<TResult>(onfulfilled: (value: T) => TResult | PromiseLike<TResult>, onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<TResult>;
4828

4929
/**
5030
* Attaches callbacks for the resolution and/or rejection of the Promise.
@@ -54,18 +34,12 @@ interface Promise<T> {
5434
*/
5535
then<TResult1, TResult2>(onfulfilled: (value: T) => TResult1 | PromiseLike<TResult1>, onrejected: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>;
5636

57-
/**
58-
* Creates a new Promise with the same internal state of this Promise.
59-
* @returns A Promise.
60-
*/
61-
catch(): Promise<T>;
62-
6337
/**
6438
* Attaches a callback for only the rejection of the Promise.
6539
* @param onrejected The callback to execute when the Promise is rejected.
6640
* @returns A Promise for the completion of the callback.
6741
*/
68-
catch(onrejected: undefined | null): Promise<T>;
42+
catch(onrejected?: ((reason: any) => T | PromiseLike<T>) | undefined | null): Promise<T>;
6943

7044
/**
7145
* Attaches a callback for only the rejection of the Promise.

src/lib/es5.d.ts

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,13 +1265,44 @@ declare type PromiseConstructorLike = new <T>(executor: (resolve: (value?: T | P
12651265

12661266
interface PromiseLike<T> {
12671267
/**
1268-
* Attaches callbacks for the resolution and/or rejection of the Promise.
1269-
* @param onfulfilled The callback to execute when the Promise is resolved.
1270-
* @param onrejected The callback to execute when the Promise is rejected.
1271-
* @returns A Promise for the completion of which ever callback is executed.
1272-
*/
1273-
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>;
1274-
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): PromiseLike<TResult>;
1268+
* Attaches callbacks for the resolution and/or rejection of the Promise.
1269+
* @param onfulfilled The callback to execute when the Promise is resolved.
1270+
* @param onrejected The callback to execute when the Promise is rejected.
1271+
* @returns A Promise for the completion of which ever callback is executed.
1272+
*/
1273+
then(
1274+
onfulfilled?: ((value: T) => T | PromiseLike<T>) | undefined | null,
1275+
onrejected?: ((reason: any) => T | PromiseLike<T>) | undefined | null): PromiseLike<T>;
1276+
1277+
/**
1278+
* Attaches callbacks for the resolution and/or rejection of the Promise.
1279+
* @param onfulfilled The callback to execute when the Promise is resolved.
1280+
* @param onrejected The callback to execute when the Promise is rejected.
1281+
* @returns A Promise for the completion of which ever callback is executed.
1282+
*/
1283+
then<TResult>(
1284+
onfulfilled: ((value: T) => T | PromiseLike<T>) | undefined | null,
1285+
onrejected: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<T | TResult>;
1286+
1287+
/**
1288+
* Attaches callbacks for the resolution and/or rejection of the Promise.
1289+
* @param onfulfilled The callback to execute when the Promise is resolved.
1290+
* @param onrejected The callback to execute when the Promise is rejected.
1291+
* @returns A Promise for the completion of which ever callback is executed.
1292+
*/
1293+
then<TResult>(
1294+
onfulfilled: (value: T) => TResult | PromiseLike<TResult>,
1295+
onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): PromiseLike<TResult>;
1296+
1297+
/**
1298+
* Attaches callbacks for the resolution and/or rejection of the Promise.
1299+
* @param onfulfilled The callback to execute when the Promise is resolved.
1300+
* @param onrejected The callback to execute when the Promise is rejected.
1301+
* @returns A Promise for the completion of which ever callback is executed.
1302+
*/
1303+
then<TResult1, TResult2>(
1304+
onfulfilled: (value: T) => TResult1 | PromiseLike<TResult1>,
1305+
onrejected: (reason: any) => TResult2 | PromiseLike<TResult2>): PromiseLike<TResult1 | TResult2>;
12751306
}
12761307

12771308
interface ArrayLike<T> {

tests/baselines/reference/inferenceLimit.symbols

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ export class BrokenClass {
3737
>reject : Symbol(reject, Decl(file1.ts, 13, 34))
3838

3939
this.doStuff(order.id)
40-
>this.doStuff(order.id) .then : Symbol(Promise.then, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
40+
>this.doStuff(order.id) .then : Symbol(Promise.then, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
4141
>this.doStuff : Symbol(BrokenClass.doStuff, Decl(file1.ts, 27, 3))
4242
>this : Symbol(BrokenClass, Decl(file1.ts, 1, 39))
4343
>doStuff : Symbol(BrokenClass.doStuff, Decl(file1.ts, 27, 3))
4444
>order : Symbol(order, Decl(file1.ts, 12, 25))
4545

4646
.then((items) => {
47-
>then : Symbol(Promise.then, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
47+
>then : Symbol(Promise.then, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
4848
>items : Symbol(items, Decl(file1.ts, 15, 17))
4949

5050
order.items = items;
@@ -60,7 +60,7 @@ export class BrokenClass {
6060
};
6161

6262
return Promise.all(result.map(populateItems))
63-
>Promise.all(result.map(populateItems)) .then : Symbol(Promise.then, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
63+
>Promise.all(result.map(populateItems)) .then : Symbol(Promise.then, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
6464
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
6565
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
6666
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
@@ -70,7 +70,7 @@ export class BrokenClass {
7070
>populateItems : Symbol(populateItems, Decl(file1.ts, 12, 7))
7171

7272
.then((orders: Array<MyModule.MyModel>) => {
73-
>then : Symbol(Promise.then, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
73+
>then : Symbol(Promise.then, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
7474
>orders : Symbol(orders, Decl(file1.ts, 23, 13))
7575
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --))
7676
>MyModule : Symbol(MyModule, Decl(file1.ts, 1, 6))

tests/baselines/reference/inferenceLimit.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class BrokenClass {
4646

4747
this.doStuff(order.id)
4848
>this.doStuff(order.id) .then((items) => { order.items = items; resolve(order); }) : Promise<void>
49-
>this.doStuff(order.id) .then : { (): Promise<void>; (onfulfilled: null): Promise<void>; <TResult>(onfulfilled: (value: void) => TResult | PromiseLike<TResult>): Promise<TResult>; (onfulfilled: null, onrejected: null): Promise<void>; <TResult>(onfulfilled: null, onrejected: (reason: any) => TResult | PromiseLike<TResult>): Promise<void | TResult>; <TResult>(onfulfilled: (value: void) => TResult | PromiseLike<TResult>, onrejected: null): Promise<TResult>; <TResult1, TResult2>(onfulfilled: (value: void) => TResult1 | PromiseLike<TResult1>, onrejected: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>; }
49+
>this.doStuff(order.id) .then : { (onfulfilled?: (value: void) => void | PromiseLike<void>, onrejected?: (reason: any) => void | PromiseLike<void>): Promise<void>; <TResult>(onfulfilled: (value: void) => void | PromiseLike<void>, onrejected: (reason: any) => TResult | PromiseLike<TResult>): Promise<void | TResult>; <TResult>(onfulfilled: (value: void) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>; <TResult1, TResult2>(onfulfilled: (value: void) => TResult1 | PromiseLike<TResult1>, onrejected: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>; }
5050
>this.doStuff(order.id) : Promise<void>
5151
>this.doStuff : (id: number) => Promise<void>
5252
>this : this
@@ -56,7 +56,7 @@ export class BrokenClass {
5656
>id : any
5757

5858
.then((items) => {
59-
>then : { (): Promise<void>; (onfulfilled: null): Promise<void>; <TResult>(onfulfilled: (value: void) => TResult | PromiseLike<TResult>): Promise<TResult>; (onfulfilled: null, onrejected: null): Promise<void>; <TResult>(onfulfilled: null, onrejected: (reason: any) => TResult | PromiseLike<TResult>): Promise<void | TResult>; <TResult>(onfulfilled: (value: void) => TResult | PromiseLike<TResult>, onrejected: null): Promise<TResult>; <TResult1, TResult2>(onfulfilled: (value: void) => TResult1 | PromiseLike<TResult1>, onrejected: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>; }
59+
>then : { (onfulfilled?: (value: void) => void | PromiseLike<void>, onrejected?: (reason: any) => void | PromiseLike<void>): Promise<void>; <TResult>(onfulfilled: (value: void) => void | PromiseLike<void>, onrejected: (reason: any) => TResult | PromiseLike<TResult>): Promise<void | TResult>; <TResult>(onfulfilled: (value: void) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>; <TResult1, TResult2>(onfulfilled: (value: void) => TResult1 | PromiseLike<TResult1>, onrejected: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>; }
6060
>(items) => { order.items = items; resolve(order); } : (items: void) => void
6161
>items : void
6262

@@ -78,7 +78,7 @@ export class BrokenClass {
7878

7979
return Promise.all(result.map(populateItems))
8080
>Promise.all(result.map(populateItems)) .then((orders: Array<MyModule.MyModel>) => { resolve(orders); }) : Promise<void>
81-
>Promise.all(result.map(populateItems)) .then : { (): Promise<{}[]>; (onfulfilled: null): Promise<{}[]>; <TResult>(onfulfilled: (value: {}[]) => TResult | PromiseLike<TResult>): Promise<TResult>; (onfulfilled: null, onrejected: null): Promise<{}[]>; <TResult>(onfulfilled: null, onrejected: (reason: any) => TResult | PromiseLike<TResult>): Promise<{}[] | TResult>; <TResult>(onfulfilled: (value: {}[]) => TResult | PromiseLike<TResult>, onrejected: null): Promise<TResult>; <TResult1, TResult2>(onfulfilled: (value: {}[]) => TResult1 | PromiseLike<TResult1>, onrejected: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>; }
81+
>Promise.all(result.map(populateItems)) .then : { (onfulfilled?: (value: {}[]) => {}[] | PromiseLike<{}[]>, onrejected?: (reason: any) => {}[] | PromiseLike<{}[]>): Promise<{}[]>; <TResult>(onfulfilled: (value: {}[]) => {}[] | PromiseLike<{}[]>, onrejected: (reason: any) => TResult | PromiseLike<TResult>): Promise<{}[] | TResult>; <TResult>(onfulfilled: (value: {}[]) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>; <TResult1, TResult2>(onfulfilled: (value: {}[]) => TResult1 | PromiseLike<TResult1>, onrejected: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>; }
8282
>Promise.all(result.map(populateItems)) : Promise<{}[]>
8383
>Promise.all : { <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>, T10 | PromiseLike<T10>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; <T1, T2, T3, T4, T5, T6, T7, T8, T9>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>, T9 | PromiseLike<T9>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; <T1, T2, T3, T4, T5, T6, T7, T8>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>, T8 | PromiseLike<T8>]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; <T1, T2, T3, T4, T5, T6, T7>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>, T7 | PromiseLike<T7>]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; <T1, T2, T3, T4, T5, T6>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>, T6 | PromiseLike<T6>]): Promise<[T1, T2, T3, T4, T5, T6]>; <T1, T2, T3, T4, T5>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>, T5 | PromiseLike<T5>]): Promise<[T1, T2, T3, T4, T5]>; <T1, T2, T3, T4>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[T1, T2, T3, T4]>; <T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>; <T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>; <T>(values: (T | PromiseLike<T>)[]): Promise<T[]>; <TAll>(values: Iterable<TAll | PromiseLike<TAll>>): Promise<TAll[]>; }
8484
>Promise : PromiseConstructor
@@ -90,7 +90,7 @@ export class BrokenClass {
9090
>populateItems : (order: any) => Promise<{}>
9191

9292
.then((orders: Array<MyModule.MyModel>) => {
93-
>then : { (): Promise<{}[]>; (onfulfilled: null): Promise<{}[]>; <TResult>(onfulfilled: (value: {}[]) => TResult | PromiseLike<TResult>): Promise<TResult>; (onfulfilled: null, onrejected: null): Promise<{}[]>; <TResult>(onfulfilled: null, onrejected: (reason: any) => TResult | PromiseLike<TResult>): Promise<{}[] | TResult>; <TResult>(onfulfilled: (value: {}[]) => TResult | PromiseLike<TResult>, onrejected: null): Promise<TResult>; <TResult1, TResult2>(onfulfilled: (value: {}[]) => TResult1 | PromiseLike<TResult1>, onrejected: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>; }
93+
>then : { (onfulfilled?: (value: {}[]) => {}[] | PromiseLike<{}[]>, onrejected?: (reason: any) => {}[] | PromiseLike<{}[]>): Promise<{}[]>; <TResult>(onfulfilled: (value: {}[]) => {}[] | PromiseLike<{}[]>, onrejected: (reason: any) => TResult | PromiseLike<TResult>): Promise<{}[] | TResult>; <TResult>(onfulfilled: (value: {}[]) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<TResult>; <TResult1, TResult2>(onfulfilled: (value: {}[]) => TResult1 | PromiseLike<TResult1>, onrejected: (reason: any) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>; }
9494
>(orders: Array<MyModule.MyModel>) => { resolve(orders); } : (orders: MyModule.MyModel[]) => void
9595
>orders : MyModule.MyModel[]
9696
>Array : T[]

0 commit comments

Comments
 (0)