diff --git a/tests/baselines/reference/correctOrderOfPromiseMethod.js b/tests/baselines/reference/correctOrderOfPromiseMethod.js index fadda95374f3e..535365b55421f 100644 --- a/tests/baselines/reference/correctOrderOfPromiseMethod.js +++ b/tests/baselines/reference/correctOrderOfPromiseMethod.js @@ -15,7 +15,7 @@ async function countEverything(): Promise { const [resultA, resultB] = await Promise.all([ providerA(), providerB(), - ] as const); + ]); const dataA: A[] = resultA; const dataB: B[] = resultB; @@ -24,6 +24,10 @@ async function countEverything(): Promise { } return 0; } + +// #31179 + +const result: Promise<[0, 1, '']> = Promise.all(undefined as readonly [0, 1, '']); //// [correctOrderOfPromiseMethod.js] @@ -92,3 +96,5 @@ function countEverything() { }); }); } +// #31179 +var result = Promise.all(undefined); diff --git a/tests/baselines/reference/correctOrderOfPromiseMethod.symbols b/tests/baselines/reference/correctOrderOfPromiseMethod.symbols index 9a62bb9fe46df..22296a221aa99 100644 --- a/tests/baselines/reference/correctOrderOfPromiseMethod.symbols +++ b/tests/baselines/reference/correctOrderOfPromiseMethod.symbols @@ -43,7 +43,7 @@ async function countEverything(): Promise { providerB(), >providerB : Symbol(providerB, Decl(correctOrderOfPromiseMethod.ts, 11, 9)) - ] as const); + ]); const dataA: A[] = resultA; >dataA : Symbol(dataA, Decl(correctOrderOfPromiseMethod.ts, 18, 9)) @@ -70,3 +70,13 @@ async function countEverything(): Promise { return 0; } +// #31179 + +const result: Promise<[0, 1, '']> = Promise.all(undefined as readonly [0, 1, '']); +>result : Symbol(result, Decl(correctOrderOfPromiseMethod.ts, 28, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>undefined : Symbol(undefined) + diff --git a/tests/baselines/reference/correctOrderOfPromiseMethod.types b/tests/baselines/reference/correctOrderOfPromiseMethod.types index 71da779a8d740..f2672d7146f58 100644 --- a/tests/baselines/reference/correctOrderOfPromiseMethod.types +++ b/tests/baselines/reference/correctOrderOfPromiseMethod.types @@ -28,13 +28,12 @@ async function countEverything(): Promise { const [resultA, resultB] = await Promise.all([ >resultA : A[] >resultB : B[] ->await Promise.all([ providerA(), providerB(), ] as const) : [A[], B[]] ->Promise.all([ providerA(), providerB(), ] as const) : Promise<[A[], B[]]> +>await Promise.all([ providerA(), providerB(), ]) : [A[], B[]] +>Promise.all([ providerA(), providerB(), ]) : Promise<[A[], B[]]> >Promise.all : { (values: Iterable): Promise<(TAll extends PromiseLike ? UAll : TAll)[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } >Promise : PromiseConstructor >all : { (values: Iterable): Promise<(TAll extends PromiseLike ? UAll : TAll)[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } ->[ providerA(), providerB(), ] as const : readonly [Promise, Promise] ->[ providerA(), providerB(), ] : readonly [Promise, Promise] +>[ providerA(), providerB(), ] : [Promise, Promise] providerA(), >providerA() : Promise @@ -44,7 +43,7 @@ async function countEverything(): Promise { >providerB() : Promise >providerB : () => Promise - ] as const); + ]); const dataA: A[] = resultA; >dataA : A[] @@ -72,3 +71,14 @@ async function countEverything(): Promise { >0 : 0 } +// #31179 + +const result: Promise<[0, 1, '']> = Promise.all(undefined as readonly [0, 1, '']); +>result : Promise<[0, 1, ""]> +>Promise.all(undefined as readonly [0, 1, '']) : Promise<[0, 1, ""]> +>Promise.all : { (values: Iterable): Promise<(TAll extends PromiseLike ? UAll : TAll)[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } +>Promise : PromiseConstructor +>all : { (values: Iterable): Promise<(TAll extends PromiseLike ? UAll : TAll)[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } +>undefined as readonly [0, 1, ''] : readonly [0, 1, ""] +>undefined : undefined + diff --git a/tests/baselines/reference/promiseType.js b/tests/baselines/reference/promiseType.js index 84d9d713b4810..f627c4a8e054b 100644 --- a/tests/baselines/reference/promiseType.js +++ b/tests/baselines/reference/promiseType.js @@ -217,6 +217,16 @@ const pc6 = p.then(() => Promise.reject("1"), () => {}); const pc7 = p.then(() => Promise.reject("1"), () => {throw 1}); const pc8 = p.then(() => Promise.reject("1"), () => Promise.resolve(1)); const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1)); + +// #28427 + +Promise.all([undefined as Promise | string]); + +Promise.resolve(undefined as Promise | string); + +// #30390 + +(undefined as Promise).then(undefined as () => Promise | string); //// [promiseType.js] @@ -440,3 +450,8 @@ const pc6 = p.then(() => Promise.reject("1"), () => { }); const pc7 = p.then(() => Promise.reject("1"), () => { throw 1; }); const pc8 = p.then(() => Promise.reject("1"), () => Promise.resolve(1)); const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1)); +// #28427 +Promise.all([undefined]); +Promise.resolve(undefined); +// #30390 +undefined.then(undefined); diff --git a/tests/baselines/reference/promiseType.symbols b/tests/baselines/reference/promiseType.symbols index cec81cd7d8266..dfd5faa29ad47 100644 --- a/tests/baselines/reference/promiseType.symbols +++ b/tests/baselines/reference/promiseType.symbols @@ -1089,3 +1089,29 @@ const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1)); >Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >reject : Symbol(PromiseConstructor.reject, Decl(lib.es2015.promise.d.ts, --, --)) +// #28427 + +Promise.all([undefined as Promise | string]); +>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>undefined : Symbol(undefined) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + +Promise.resolve(undefined as Promise | string); +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>undefined : Symbol(undefined) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + +// #30390 + +(undefined as Promise).then(undefined as () => Promise | string); +>(undefined as Promise).then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>undefined : Symbol(undefined) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>undefined : Symbol(undefined) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + diff --git a/tests/baselines/reference/promiseType.types b/tests/baselines/reference/promiseType.types index e0580f999033d..b819582ecdf26 100644 --- a/tests/baselines/reference/promiseType.types +++ b/tests/baselines/reference/promiseType.types @@ -1583,3 +1583,34 @@ const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1)); >reject : (reason?: any) => Promise >1 : 1 +// #28427 + +Promise.all([undefined as Promise | string]); +>Promise.all([undefined as Promise | string]) : Promise<(string | number)[]> +>Promise.all : { (values: Iterable): Promise<(TAll extends PromiseLike ? UAll : TAll)[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } +>Promise : PromiseConstructor +>all : { (values: Iterable): Promise<(TAll extends PromiseLike ? UAll : TAll)[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } +>[undefined as Promise | string] : (string | Promise)[] +>undefined as Promise | string : string | Promise +>undefined : undefined + +Promise.resolve(undefined as Promise | string); +>Promise.resolve(undefined as Promise | string) : Promise +>Promise.resolve : { (value: T): Promise>; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T): Promise>; (): Promise; } +>undefined as Promise | string : string | Promise +>undefined : undefined + +// #30390 + +(undefined as Promise).then(undefined as () => Promise | string); +>(undefined as Promise).then(undefined as () => Promise | string) : Promise +>(undefined as Promise).then : (onfulfilled?: (value: any) => TResult1, onrejected?: (reason: any) => TResult2) => Promise<(TResult1 extends PromiseLike ? UResult1 : TResult1) | (TResult2 extends PromiseLike ? UResult2 : TResult2)> +>(undefined as Promise) : Promise +>undefined as Promise : Promise +>undefined : undefined +>then : (onfulfilled?: (value: any) => TResult1, onrejected?: (reason: any) => TResult2) => Promise<(TResult1 extends PromiseLike ? UResult1 : TResult1) | (TResult2 extends PromiseLike ? UResult2 : TResult2)> +>undefined as () => Promise | string : () => string | Promise +>undefined : undefined + diff --git a/tests/cases/compiler/correctOrderOfPromiseMethod.ts b/tests/cases/compiler/correctOrderOfPromiseMethod.ts index 70c730c6b20b1..6c7136f062b35 100644 --- a/tests/cases/compiler/correctOrderOfPromiseMethod.ts +++ b/tests/cases/compiler/correctOrderOfPromiseMethod.ts @@ -17,7 +17,7 @@ async function countEverything(): Promise { const [resultA, resultB] = await Promise.all([ providerA(), providerB(), - ] as const); + ]); const dataA: A[] = resultA; const dataB: B[] = resultB; @@ -26,3 +26,7 @@ async function countEverything(): Promise { } return 0; } + +// #31179 + +const result: Promise<[0, 1, '']> = Promise.all(undefined as readonly [0, 1, '']); diff --git a/tests/cases/compiler/promiseType.ts b/tests/cases/compiler/promiseType.ts index ba4a7f6041396..fca2c36c1fb34 100644 --- a/tests/cases/compiler/promiseType.ts +++ b/tests/cases/compiler/promiseType.ts @@ -217,3 +217,13 @@ const pc6 = p.then(() => Promise.reject("1"), () => {}); const pc7 = p.then(() => Promise.reject("1"), () => {throw 1}); const pc8 = p.then(() => Promise.reject("1"), () => Promise.resolve(1)); const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1)); + +// #28427 + +Promise.all([undefined as Promise | string]); + +Promise.resolve(undefined as Promise | string); + +// #30390 + +(undefined as Promise).then(undefined as () => Promise | string);