diff --git a/tests/baselines/reference/asyncFunctionReturnType.js b/tests/baselines/reference/asyncFunctionReturnType.js index fcb5d74ffaa2b..dce0f07b77cec 100644 --- a/tests/baselines/reference/asyncFunctionReturnType.js +++ b/tests/baselines/reference/asyncFunctionReturnType.js @@ -74,6 +74,13 @@ async function fGenericIndexedTypeForPromiseOfKProp(obj: TObj, key: K): Promise> { return Promise.resolve(obj[key]); } + +// #27711 + +async function fGeneric(x: T) { + return x; +} +const expected: Promise = fGeneric(undefined as Promise); //// [asyncFunctionReturnType.js] @@ -173,3 +180,10 @@ function fGenericIndexedTypeForExplicitPromiseOfKProp(obj, key) { return Promise.resolve(obj[key]); }); } +// #27711 +function fGeneric(x) { + return __awaiter(this, void 0, void 0, function* () { + return x; + }); +} +const expected = fGeneric(undefined); diff --git a/tests/baselines/reference/asyncFunctionReturnType.symbols b/tests/baselines/reference/asyncFunctionReturnType.symbols index 7012f28ae015e..7b0c95c33acb8 100644 --- a/tests/baselines/reference/asyncFunctionReturnType.symbols +++ b/tests/baselines/reference/asyncFunctionReturnType.symbols @@ -289,3 +289,21 @@ async function fGenericIndexedTypeForExplicitPromiseOfKPropkey : Symbol(key, Decl(asyncFunctionReturnType.ts, 72, 110)) } +// #27711 + +async function fGeneric(x: T) { +>fGeneric : Symbol(fGeneric, Decl(asyncFunctionReturnType.ts, 74, 1)) +>T : Symbol(T, Decl(asyncFunctionReturnType.ts, 78, 24)) +>x : Symbol(x, Decl(asyncFunctionReturnType.ts, 78, 27)) +>T : Symbol(T, Decl(asyncFunctionReturnType.ts, 78, 24)) + + return x; +>x : Symbol(x, Decl(asyncFunctionReturnType.ts, 78, 27)) +} +const expected: Promise = fGeneric(undefined as Promise); +>expected : Symbol(expected, Decl(asyncFunctionReturnType.ts, 81, 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, --, --)) +>fGeneric : Symbol(fGeneric, Decl(asyncFunctionReturnType.ts, 74, 1)) +>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/asyncFunctionReturnType.types b/tests/baselines/reference/asyncFunctionReturnType.types index 5cff71ae457d1..e8e68fb0ab587 100644 --- a/tests/baselines/reference/asyncFunctionReturnType.types +++ b/tests/baselines/reference/asyncFunctionReturnType.types @@ -221,3 +221,19 @@ async function fGenericIndexedTypeForExplicitPromiseOfKPropkey : K } +// #27711 + +async function fGeneric(x: T) { +>fGeneric : (x: T) => Promise> +>x : T + + return x; +>x : T +} +const expected: Promise = fGeneric(undefined as Promise); +>expected : Promise +>fGeneric(undefined as Promise) : Promise +>fGeneric : (x: T) => Promise> +>undefined as Promise : Promise +>undefined : undefined + diff --git a/tests/baselines/reference/correctOrderOfPromiseMethod.js b/tests/baselines/reference/correctOrderOfPromiseMethod.js index fadda95374f3e..81a91ba06fd81 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 expected: Promise<["a", "b", "c"]> = Promise.all(undefined as readonly ["a", "b", "c"]); //// [correctOrderOfPromiseMethod.js] @@ -92,3 +96,5 @@ function countEverything() { }); }); } +// #31179 +var expected = Promise.all(undefined); diff --git a/tests/baselines/reference/correctOrderOfPromiseMethod.symbols b/tests/baselines/reference/correctOrderOfPromiseMethod.symbols index 9a62bb9fe46df..6efd2fdd69fc8 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 expected: Promise<["a", "b", "c"]> = Promise.all(undefined as readonly ["a", "b", "c"]); +>expected : Symbol(expected, 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 78e7fce9b5586..226858f0fe2ee 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[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } >Promise : PromiseConstructor >all : { (values: Iterable): Promise[]>; (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 expected: Promise<["a", "b", "c"]> = Promise.all(undefined as readonly ["a", "b", "c"]); +>expected : Promise<["a", "b", "c"]> +>Promise.all(undefined as readonly ["a", "b", "c"]) : Promise<["a", "b", "c"]> +>Promise.all : { (values: Iterable): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } +>Promise : PromiseConstructor +>all : { (values: Iterable): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } +>undefined as readonly ["a", "b", "c"] : readonly ["a", "b", "c"] +>undefined : undefined + diff --git a/tests/baselines/reference/promiseType.js b/tests/baselines/reference/promiseType.js index 84d9d713b4810..b9dadc71d0074 100644 --- a/tests/baselines/reference/promiseType.js +++ b/tests/baselines/reference/promiseType.js @@ -217,6 +217,14 @@ 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)); + +const expected: undefined = undefined as Awaited; + +// #28427 + +Promise.all([undefined as Promise | number]); + +Promise.resolve(undefined as Promise | number); //// [promiseType.js] @@ -440,3 +448,7 @@ 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)); +const expected = undefined; +// #28427 +Promise.all([undefined]); +Promise.resolve(undefined); diff --git a/tests/baselines/reference/promiseType.symbols b/tests/baselines/reference/promiseType.symbols index cec81cd7d8266..13f569a95aa68 100644 --- a/tests/baselines/reference/promiseType.symbols +++ b/tests/baselines/reference/promiseType.symbols @@ -1089,3 +1089,24 @@ 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, --, --)) +const expected: undefined = undefined as Awaited; +>expected : Symbol(expected, Decl(promiseType.ts, 219, 5)) +>undefined : Symbol(undefined) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +// #28427 + +Promise.all([undefined as Promise | number]); +>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 | number); +>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, --, --)) + diff --git a/tests/baselines/reference/promiseType.types b/tests/baselines/reference/promiseType.types index b57545ef2def8..49862f62d9221 100644 --- a/tests/baselines/reference/promiseType.types +++ b/tests/baselines/reference/promiseType.types @@ -1583,3 +1583,27 @@ const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1)); >reject : (reason?: any) => Promise >1 : 1 +const expected: undefined = undefined as Awaited; +>expected : undefined +>undefined as Awaited : undefined +>undefined : undefined + +// #28427 + +Promise.all([undefined as Promise | number]); +>Promise.all([undefined as Promise | number]) : Promise<(string | number)[]> +>Promise.all : { (values: Iterable): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } +>Promise : PromiseConstructor +>all : { (values: Iterable): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } +>[undefined as Promise | number] : (number | Promise)[] +>undefined as Promise | number : number | Promise +>undefined : undefined + +Promise.resolve(undefined as Promise | number); +>Promise.resolve(undefined as Promise | number) : Promise +>Promise.resolve : { (value: T): Promise>; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T): Promise>; (): Promise; } +>undefined as Promise | number : number | Promise +>undefined : undefined + diff --git a/tests/cases/compiler/asyncFunctionReturnType.ts b/tests/cases/compiler/asyncFunctionReturnType.ts index 3192aa17616ae..d8c04e8ba6d60 100644 --- a/tests/cases/compiler/asyncFunctionReturnType.ts +++ b/tests/cases/compiler/asyncFunctionReturnType.ts @@ -74,3 +74,10 @@ async function fGenericIndexedTypeForPromiseOfKProp(obj: TObj, key: K): Promise> { return Promise.resolve(obj[key]); } + +// #27711 + +async function fGeneric(x: T) { + return x; +} +const expected: Promise = fGeneric(undefined as Promise); diff --git a/tests/cases/compiler/correctOrderOfPromiseMethod.ts b/tests/cases/compiler/correctOrderOfPromiseMethod.ts index 70c730c6b20b1..7ece852204825 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 expected: Promise<["a", "b", "c"]> = Promise.all(undefined as readonly ["a", "b", "c"]); diff --git a/tests/cases/compiler/promiseType.ts b/tests/cases/compiler/promiseType.ts index ba4a7f6041396..c9eb9fbd7fb97 100644 --- a/tests/cases/compiler/promiseType.ts +++ b/tests/cases/compiler/promiseType.ts @@ -217,3 +217,11 @@ 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)); + +const expected: undefined = undefined as Awaited; + +// #28427 + +Promise.all([undefined as Promise | number]); + +Promise.resolve(undefined as Promise | number);