Skip to content

Commit

Permalink
Adjust overloads to fix #10524.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Sep 6, 2016
1 parent ab2750a commit 9d4219a
Show file tree
Hide file tree
Showing 16 changed files with 614 additions and 609 deletions.
34 changes: 4 additions & 30 deletions src/lib/es2015.promise.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,29 @@
* Represents the completion of an asynchronous operation
*/
interface Promise<T> {
/**
* Creates a new Promise with the same internal state of this Promise.
* @returns A Promise.
*/
then(): Promise<T>;

/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
* @returns A Promise for the completion of which ever callback is executed.
*/
then(onfulfilled: undefined | null): Promise<T>;

/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
* @returns A Promise for the completion of which ever callback is executed.
*/
then<TResult>(onfulfilled: (value: T) => TResult | PromiseLike<TResult>): Promise<TResult>;

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

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

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

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

/**
* Creates a new Promise with the same internal state of this Promise.
* @returns A Promise.
*/
catch(): Promise<T>;

/**
* Attaches a callback for only the rejection of the Promise.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of the callback.
*/
catch(onrejected: undefined | null): Promise<T>;
catch(onrejected?: ((reason: any) => T | PromiseLike<T>) | undefined | null): Promise<T>;

/**
* Attaches a callback for only the rejection of the Promise.
Expand Down
45 changes: 38 additions & 7 deletions src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1265,13 +1265,44 @@ declare type PromiseConstructorLike = new <T>(executor: (resolve: (value?: T | P

interface PromiseLike<T> {
/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of which ever callback is executed.
*/
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>): PromiseLike<TResult>;
then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): PromiseLike<TResult>;
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of which ever callback is executed.
*/
then(
onfulfilled?: ((value: T) => T | PromiseLike<T>) | undefined | null,
onrejected?: ((reason: any) => T | PromiseLike<T>) | undefined | null): PromiseLike<T>;

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

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

/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of which ever callback is executed.
*/
then<TResult1, TResult2>(
onfulfilled: (value: T) => TResult1 | PromiseLike<TResult1>,
onrejected: (reason: any) => TResult2 | PromiseLike<TResult2>): PromiseLike<TResult1 | TResult2>;
}

interface ArrayLike<T> {
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/inferenceLimit.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ export class BrokenClass {
>reject : Symbol(reject, Decl(file1.ts, 13, 34))

this.doStuff(order.id)
>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, --, --))
>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, --, --))
>this.doStuff : Symbol(BrokenClass.doStuff, Decl(file1.ts, 27, 3))
>this : Symbol(BrokenClass, Decl(file1.ts, 1, 39))
>doStuff : Symbol(BrokenClass.doStuff, Decl(file1.ts, 27, 3))
>order : Symbol(order, Decl(file1.ts, 12, 25))

.then((items) => {
>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, --, --))
>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, --, --))
>items : Symbol(items, Decl(file1.ts, 15, 17))

order.items = items;
Expand All @@ -60,7 +60,7 @@ export class BrokenClass {
};

return Promise.all(result.map(populateItems))
>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, --, --))
>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, --, --))
>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, --, --))
>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, --, --))
>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, --, --))
Expand All @@ -70,7 +70,7 @@ export class BrokenClass {
>populateItems : Symbol(populateItems, Decl(file1.ts, 12, 7))

.then((orders: Array<MyModule.MyModel>) => {
>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, --, --))
>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, --, --))
>orders : Symbol(orders, Decl(file1.ts, 23, 13))
>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, --, --))
>MyModule : Symbol(MyModule, Decl(file1.ts, 1, 6))
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/inferenceLimit.types
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class BrokenClass {

this.doStuff(order.id)
>this.doStuff(order.id) .then((items) => { order.items = items; resolve(order); }) : Promise<void>
>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>; }
>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>; }
>this.doStuff(order.id) : Promise<void>
>this.doStuff : (id: number) => Promise<void>
>this : this
Expand All @@ -56,7 +56,7 @@ export class BrokenClass {
>id : any

.then((items) => {
>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>; }
>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>; }
>(items) => { order.items = items; resolve(order); } : (items: void) => void
>items : void

Expand All @@ -78,7 +78,7 @@ export class BrokenClass {

return Promise.all(result.map(populateItems))
>Promise.all(result.map(populateItems)) .then((orders: Array<MyModule.MyModel>) => { resolve(orders); }) : Promise<void>
>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>; }
>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>; }
>Promise.all(result.map(populateItems)) : Promise<{}[]>
>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[]>; }
>Promise : PromiseConstructor
Expand All @@ -90,7 +90,7 @@ export class BrokenClass {
>populateItems : (order: any) => Promise<{}>

.then((orders: Array<MyModule.MyModel>) => {
>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>; }
>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>; }
>(orders: Array<MyModule.MyModel>) => { resolve(orders); } : (orders: MyModule.MyModel[]) => void
>orders : MyModule.MyModel[]
>Array : T[]
Expand Down
Loading

0 comments on commit 9d4219a

Please sign in to comment.