From 46ce88c56522d8e8d4ae8af571996a3d55c999a7 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 6 Aug 2021 19:47:14 -0700 Subject: [PATCH 1/4] Adds 'Awaited' type alias and updates to Promise.all/race/allSettled/any --- src/harness/fourslashInterfaceImpl.ts | 1 + src/lib/es2015.promise.d.ts | 16 ++ src/lib/es2020.promise.d.ts | 3 +- src/lib/es2021.promise.d.ts | 7 + src/lib/es5.d.ts | 11 ++ .../asyncArrowFunction9_es2017.errors.txt | 2 +- .../asyncArrowFunction9_es5.errors.txt | 2 +- .../asyncArrowFunction9_es6.errors.txt | 2 +- .../reference/awaitedType.errors.txt | 52 ++++++ tests/baselines/reference/awaitedType.js | 58 ++++++ tests/baselines/reference/awaitedType.symbols | 171 ++++++++++++++++++ tests/baselines/reference/awaitedType.types | 134 ++++++++++++++ .../awaitedTypeStrictNull.errors.txt | 52 ++++++ .../reference/awaitedTypeStrictNull.js | 58 ++++++ .../reference/awaitedTypeStrictNull.symbols | 171 ++++++++++++++++++ .../reference/awaitedTypeStrictNull.types | 134 ++++++++++++++ .../correctOrderOfPromiseMethod.symbols | 8 +- .../correctOrderOfPromiseMethod.types | 8 +- ...ferFromGenericFunctionReturnTypes3.symbols | 4 +- ...inferFromGenericFunctionReturnTypes3.types | 10 +- .../reference/inferenceLimit.symbols | 4 +- .../baselines/reference/inferenceLimit.types | 4 +- .../reference/mappedTypesArraysTuples.js | 8 +- .../reference/mappedTypesArraysTuples.symbols | 32 ++-- .../reference/mappedTypesArraysTuples.types | 6 +- .../recursiveConditionalTypes.errors.txt | 30 +-- .../reference/recursiveConditionalTypes.js | 22 +-- .../recursiveConditionalTypes.symbols | 50 ++--- .../reference/recursiveConditionalTypes.types | 38 ++-- tests/cases/compiler/awaitedType.ts | 45 +++++ tests/cases/compiler/awaitedTypeStrictNull.ts | 45 +++++ .../compiler/recursiveConditionalTypes.ts | 12 +- .../types/mapped/mappedTypesArraysTuples.ts | 4 +- 33 files changed, 1079 insertions(+), 125 deletions(-) create mode 100644 tests/baselines/reference/awaitedType.errors.txt create mode 100644 tests/baselines/reference/awaitedType.js create mode 100644 tests/baselines/reference/awaitedType.symbols create mode 100644 tests/baselines/reference/awaitedType.types create mode 100644 tests/baselines/reference/awaitedTypeStrictNull.errors.txt create mode 100644 tests/baselines/reference/awaitedTypeStrictNull.js create mode 100644 tests/baselines/reference/awaitedTypeStrictNull.symbols create mode 100644 tests/baselines/reference/awaitedTypeStrictNull.types create mode 100644 tests/cases/compiler/awaitedType.ts create mode 100644 tests/cases/compiler/awaitedTypeStrictNull.ts diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index ef3471866e223..aeaa0566d6dad 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -1079,6 +1079,7 @@ namespace FourSlashInterface { typeEntry("PromiseConstructorLike"), interfaceEntry("PromiseLike"), interfaceEntry("Promise"), + typeEntry("Awaited"), interfaceEntry("ArrayLike"), typeEntry("Partial"), typeEntry("Required"), diff --git a/src/lib/es2015.promise.d.ts b/src/lib/es2015.promise.d.ts index 7d31dc9668577..e8c6ce477dde1 100644 --- a/src/lib/es2015.promise.d.ts +++ b/src/lib/es2015.promise.d.ts @@ -12,6 +12,14 @@ interface PromiseConstructor { */ new (executor: (resolve: (value: T | PromiseLike) => void, reject: (reason?: any) => void) => void): Promise; + /** + * Creates a Promise that is resolved with an array of results when all of the provided Promises + * resolve, or rejected when any Promise is rejected. + * @param values An array of Promises. + * @returns A new Promise. + */ + all(values: T): Promise<{ -readonly [P in keyof T]: Awaited }>; + /** * Creates a Promise that is resolved with an array of results when all of the provided Promises * resolve, or rejected when any Promise is rejected. @@ -95,6 +103,14 @@ interface PromiseConstructor { // see: lib.es2015.iterable.d.ts // all(values: Iterable>): Promise; + /** + * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved + * or rejected. + * @param values An array of Promises. + * @returns A new Promise. + */ + race(values: T): Promise>; + /** * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved * or rejected. diff --git a/src/lib/es2020.promise.d.ts b/src/lib/es2020.promise.d.ts index a996a99603e5d..f6dd5e4e65184 100644 --- a/src/lib/es2020.promise.d.ts +++ b/src/lib/es2020.promise.d.ts @@ -17,8 +17,7 @@ interface PromiseConstructor { * @param values An array of Promises. * @returns A new Promise. */ - allSettled(values: T): - Promise<{ -readonly [P in keyof T]: PromiseSettledResult ? U : T[P]> }>; + allSettled(values: T): Promise<{ -readonly [P in keyof T]: PromiseSettledResult> }>; /** * Creates a Promise that is resolved with an array of results when all diff --git a/src/lib/es2021.promise.d.ts b/src/lib/es2021.promise.d.ts index d18a16581426b..4561908ebf584 100644 --- a/src/lib/es2021.promise.d.ts +++ b/src/lib/es2021.promise.d.ts @@ -14,6 +14,13 @@ declare var AggregateError: AggregateErrorConstructor; * Represents the completion of an asynchronous operation */ interface PromiseConstructor { + /** + * The any function returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError containing an array of rejection reasons if all of the given promises are rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm. + * @param values An array or iterable of Promises. + * @returns A new Promise. + */ + any(values: T): Promise>; + /** * The any function returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError containing an array of rejection reasons if all of the given promises are rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm. * @param values An array or iterable of Promises. diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 461d98977730d..b7199804fb326 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1440,6 +1440,17 @@ interface Promise { catch(onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null): Promise; } +/** + * Recursively unwraps the "awaited type" of a type. Non-promise "thenables" should resolve to `never`. This emulates the behavior of `await`. + */ +type Awaited = + T extends null | undefined ? T : // special case for `null | undefined` when not in `--noImplicitAny` mode + T extends { then(onfulfilled: infer F): any } ? // thenable, extracts the first argument to `then()` + F extends ((value: infer V) => any) ? // if the argument to `then` is callable, extracts the argument + Awaited : // recursively unwrap the value + never : // the argument to `then` was not callable. + T; // non-thenable + interface ArrayLike { readonly length: number; readonly [n: number]: T; diff --git a/tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt b/tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt index ce7aaa8db1f8a..ed8dacf90fccd 100644 --- a/tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt +++ b/tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt @@ -16,7 +16,7 @@ tests/cases/conformance/async/es2017/asyncArrowFunction/asyncArrowFunction9_es20 !!! error TS1005: ',' expected. ~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'. -!!! related TS6203 /.ts/lib.es2015.promise.d.ts:150:13: 'Promise' was also declared here. +!!! related TS6203 /.ts/lib.es2015.promise.d.ts:166:13: 'Promise' was also declared here. ~ !!! error TS1005: ',' expected. ~~ diff --git a/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt b/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt index 447b8c124f9cf..4df3d4b80f83a 100644 --- a/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt +++ b/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt @@ -16,7 +16,7 @@ tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts( !!! error TS1005: ',' expected. ~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'. -!!! related TS6203 /.ts/lib.es2015.promise.d.ts:150:13: 'Promise' was also declared here. +!!! related TS6203 /.ts/lib.es2015.promise.d.ts:166:13: 'Promise' was also declared here. ~ !!! error TS1005: ',' expected. ~~ diff --git a/tests/baselines/reference/asyncArrowFunction9_es6.errors.txt b/tests/baselines/reference/asyncArrowFunction9_es6.errors.txt index 636d8e6e1c674..b84f6692e0d67 100644 --- a/tests/baselines/reference/asyncArrowFunction9_es6.errors.txt +++ b/tests/baselines/reference/asyncArrowFunction9_es6.errors.txt @@ -16,7 +16,7 @@ tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts( !!! error TS1005: ',' expected. ~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'. -!!! related TS6203 /.ts/lib.es2015.promise.d.ts:150:13: 'Promise' was also declared here. +!!! related TS6203 /.ts/lib.es2015.promise.d.ts:166:13: 'Promise' was also declared here. ~ !!! error TS1005: ',' expected. ~~ diff --git a/tests/baselines/reference/awaitedType.errors.txt b/tests/baselines/reference/awaitedType.errors.txt new file mode 100644 index 0000000000000..27441196136b1 --- /dev/null +++ b/tests/baselines/reference/awaitedType.errors.txt @@ -0,0 +1,52 @@ +tests/cases/compiler/awaitedType.ts(18,12): error TS2589: Type instantiation is excessively deep and possibly infinite. +tests/cases/compiler/awaitedType.ts(22,12): error TS2589: Type instantiation is excessively deep and possibly infinite. + + +==== tests/cases/compiler/awaitedType.ts (2 errors) ==== + type T1 = Awaited; + type T2 = Awaited>; + type T3 = Awaited>; + type T4 = Awaited>; + type T5 = Awaited<{ then: number }>; + type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable") + type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable") + type T8 = Awaited<{ then(x: () => void): void }>; // unknown + type T9 = Awaited; + type T10 = Awaited; + type T11 = Awaited; + type T12 = Awaited>>; + type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful + type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful + type T15 = _Expect> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful + + interface BadPromise { then(cb: (value: BadPromise) => void): void; } + type T16 = Awaited; // error + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2589: Type instantiation is excessively deep and possibly infinite. + + interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; } + interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; } + type T17 = Awaited; // error + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2589: Type instantiation is excessively deep and possibly infinite. + + // https://github.com/microsoft/TypeScript/issues/33562 + type MaybePromise = T | Promise | PromiseLike + declare function MaybePromise(value: T): MaybePromise; + + async function main() { + let aaa: number; + let bbb: string; + [ + aaa, + bbb, + ] = await Promise.all([ + MaybePromise(1), + MaybePromise('2'), + MaybePromise(true), + ]) + } + + // helps with tests where '.types' just prints out the type alias name + type _Expect = TActual; + \ No newline at end of file diff --git a/tests/baselines/reference/awaitedType.js b/tests/baselines/reference/awaitedType.js new file mode 100644 index 0000000000000..57ad66fa51fb9 --- /dev/null +++ b/tests/baselines/reference/awaitedType.js @@ -0,0 +1,58 @@ +//// [awaitedType.ts] +type T1 = Awaited; +type T2 = Awaited>; +type T3 = Awaited>; +type T4 = Awaited>; +type T5 = Awaited<{ then: number }>; +type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable") +type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable") +type T8 = Awaited<{ then(x: () => void): void }>; // unknown +type T9 = Awaited; +type T10 = Awaited; +type T11 = Awaited; +type T12 = Awaited>>; +type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful +type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful +type T15 = _Expect> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful + +interface BadPromise { then(cb: (value: BadPromise) => void): void; } +type T16 = Awaited; // error + +interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; } +interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; } +type T17 = Awaited; // error + +// https://github.com/microsoft/TypeScript/issues/33562 +type MaybePromise = T | Promise | PromiseLike +declare function MaybePromise(value: T): MaybePromise; + +async function main() { + let aaa: number; + let bbb: string; + [ + aaa, + bbb, + ] = await Promise.all([ + MaybePromise(1), + MaybePromise('2'), + MaybePromise(true), + ]) +} + +// helps with tests where '.types' just prints out the type alias name +type _Expect = TActual; + + +//// [awaitedType.js] +async function main() { + let aaa; + let bbb; + [ + aaa, + bbb, + ] = await Promise.all([ + MaybePromise(1), + MaybePromise('2'), + MaybePromise(true), + ]); +} diff --git a/tests/baselines/reference/awaitedType.symbols b/tests/baselines/reference/awaitedType.symbols new file mode 100644 index 0000000000000..635dc89f2c6f5 --- /dev/null +++ b/tests/baselines/reference/awaitedType.symbols @@ -0,0 +1,171 @@ +=== tests/cases/compiler/awaitedType.ts === +type T1 = Awaited; +>T1 : Symbol(T1, Decl(awaitedType.ts, 0, 0)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T2 = Awaited>; +>T2 : Symbol(T2, Decl(awaitedType.ts, 0, 26)) +>Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + +type T3 = Awaited>; +>T3 : Symbol(T3, Decl(awaitedType.ts, 1, 35)) +>Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + +type T4 = Awaited>; +>T4 : Symbol(T4, Decl(awaitedType.ts, 2, 44)) +>Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + +type T5 = Awaited<{ then: number }>; +>T5 : Symbol(T5, Decl(awaitedType.ts, 3, 44)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedType.ts, 4, 19)) + +type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable") +>T6 : Symbol(T6, Decl(awaitedType.ts, 4, 36)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedType.ts, 5, 19)) + +type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable") +>T7 : Symbol(T7, Decl(awaitedType.ts, 5, 36)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedType.ts, 6, 19)) +>x : Symbol(x, Decl(awaitedType.ts, 6, 25)) + +type T8 = Awaited<{ then(x: () => void): void }>; // unknown +>T8 : Symbol(T8, Decl(awaitedType.ts, 6, 45)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedType.ts, 7, 19)) +>x : Symbol(x, Decl(awaitedType.ts, 7, 25)) + +type T9 = Awaited; +>T9 : Symbol(T9, Decl(awaitedType.ts, 7, 49)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T10 = Awaited; +>T10 : Symbol(T10, Decl(awaitedType.ts, 8, 23)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T11 = Awaited; +>T11 : Symbol(T11, Decl(awaitedType.ts, 9, 26)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T12 = Awaited>>; +>T12 : Symbol(T12, Decl(awaitedType.ts, 10, 28)) +>Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + +type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful +>T13 : Symbol(T13, Decl(awaitedType.ts, 11, 45)) +>_Expect : Symbol(_Expect, Decl(awaitedType.ts, 38, 1)) +>Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + +type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful +>T14 : Symbol(T14, Decl(awaitedType.ts, 12, 107)) +>_Expect : Symbol(_Expect, Decl(awaitedType.ts, 38, 1)) +>Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + +type T15 = _Expect> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful +>T15 : Symbol(T15, Decl(awaitedType.ts, 13, 117)) +>_Expect : Symbol(_Expect, Decl(awaitedType.ts, 38, 1)) +>Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + +interface BadPromise { then(cb: (value: BadPromise) => void): void; } +>BadPromise : Symbol(BadPromise, Decl(awaitedType.ts, 14, 131)) +>then : Symbol(BadPromise.then, Decl(awaitedType.ts, 16, 22)) +>cb : Symbol(cb, Decl(awaitedType.ts, 16, 28)) +>value : Symbol(value, Decl(awaitedType.ts, 16, 33)) +>BadPromise : Symbol(BadPromise, Decl(awaitedType.ts, 14, 131)) + +type T16 = Awaited; // error +>T16 : Symbol(T16, Decl(awaitedType.ts, 16, 69)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>BadPromise : Symbol(BadPromise, Decl(awaitedType.ts, 14, 131)) + +interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; } +>BadPromise1 : Symbol(BadPromise1, Decl(awaitedType.ts, 17, 31)) +>then : Symbol(BadPromise1.then, Decl(awaitedType.ts, 19, 23)) +>cb : Symbol(cb, Decl(awaitedType.ts, 19, 29)) +>value : Symbol(value, Decl(awaitedType.ts, 19, 34)) +>BadPromise2 : Symbol(BadPromise2, Decl(awaitedType.ts, 19, 71)) + +interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; } +>BadPromise2 : Symbol(BadPromise2, Decl(awaitedType.ts, 19, 71)) +>then : Symbol(BadPromise2.then, Decl(awaitedType.ts, 20, 23)) +>cb : Symbol(cb, Decl(awaitedType.ts, 20, 29)) +>value : Symbol(value, Decl(awaitedType.ts, 20, 34)) +>BadPromise1 : Symbol(BadPromise1, Decl(awaitedType.ts, 17, 31)) + +type T17 = Awaited; // error +>T17 : Symbol(T17, Decl(awaitedType.ts, 20, 71)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>BadPromise1 : Symbol(BadPromise1, Decl(awaitedType.ts, 17, 31)) + +// https://github.com/microsoft/TypeScript/issues/33562 +type MaybePromise = T | Promise | PromiseLike +>MaybePromise : Symbol(MaybePromise, Decl(awaitedType.ts, 24, 54), Decl(awaitedType.ts, 21, 32)) +>T : Symbol(T, Decl(awaitedType.ts, 24, 18)) +>T : Symbol(T, Decl(awaitedType.ts, 24, 18)) +>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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>T : Symbol(T, Decl(awaitedType.ts, 24, 18)) +>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(awaitedType.ts, 24, 18)) + +declare function MaybePromise(value: T): MaybePromise; +>MaybePromise : Symbol(MaybePromise, Decl(awaitedType.ts, 24, 54), Decl(awaitedType.ts, 21, 32)) +>T : Symbol(T, Decl(awaitedType.ts, 25, 30)) +>value : Symbol(value, Decl(awaitedType.ts, 25, 33)) +>T : Symbol(T, Decl(awaitedType.ts, 25, 30)) +>MaybePromise : Symbol(MaybePromise, Decl(awaitedType.ts, 24, 54), Decl(awaitedType.ts, 21, 32)) +>T : Symbol(T, Decl(awaitedType.ts, 25, 30)) + +async function main() { +>main : Symbol(main, Decl(awaitedType.ts, 25, 60)) + + let aaa: number; +>aaa : Symbol(aaa, Decl(awaitedType.ts, 28, 7)) + + let bbb: string; +>bbb : Symbol(bbb, Decl(awaitedType.ts, 29, 7)) + + [ + aaa, +>aaa : Symbol(aaa, Decl(awaitedType.ts, 28, 7)) + + bbb, +>bbb : Symbol(bbb, Decl(awaitedType.ts, 29, 7)) + + ] = await Promise.all([ +>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) +>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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) + + MaybePromise(1), +>MaybePromise : Symbol(MaybePromise, Decl(awaitedType.ts, 24, 54), Decl(awaitedType.ts, 21, 32)) + + MaybePromise('2'), +>MaybePromise : Symbol(MaybePromise, Decl(awaitedType.ts, 24, 54), Decl(awaitedType.ts, 21, 32)) + + MaybePromise(true), +>MaybePromise : Symbol(MaybePromise, Decl(awaitedType.ts, 24, 54), Decl(awaitedType.ts, 21, 32)) + + ]) +} + +// helps with tests where '.types' just prints out the type alias name +type _Expect = TActual; +>_Expect : Symbol(_Expect, Decl(awaitedType.ts, 38, 1)) +>TActual : Symbol(TActual, Decl(awaitedType.ts, 41, 13)) +>TExpected : Symbol(TExpected, Decl(awaitedType.ts, 41, 39)) +>TExpected : Symbol(TExpected, Decl(awaitedType.ts, 41, 39)) +>TActual : Symbol(TActual, Decl(awaitedType.ts, 41, 13)) + diff --git a/tests/baselines/reference/awaitedType.types b/tests/baselines/reference/awaitedType.types new file mode 100644 index 0000000000000..56757e19e9bf4 --- /dev/null +++ b/tests/baselines/reference/awaitedType.types @@ -0,0 +1,134 @@ +=== tests/cases/compiler/awaitedType.ts === +type T1 = Awaited; +>T1 : number + +type T2 = Awaited>; +>T2 : number + +type T3 = Awaited>; +>T3 : number + +type T4 = Awaited>; +>T4 : T4 + +type T5 = Awaited<{ then: number }>; +>T5 : { then: number; } +>then : number + +type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable") +>T6 : never +>then : () => void + +type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable") +>T7 : never +>then : (x: number) => void +>x : number + +type T8 = Awaited<{ then(x: () => void): void }>; // unknown +>T8 : unknown +>then : (x: () => void) => void +>x : () => void + +type T9 = Awaited; +>T9 : any + +type T10 = Awaited; +>T10 : never + +type T11 = Awaited; +>T11 : unknown + +type T12 = Awaited>>; +>T12 : number + +type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful +>T13 : string | number +>null : null +>null : null + +type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful +>T14 : string | number + +type T15 = _Expect> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful +>T15 : string | number +>null : null +>null : null + +interface BadPromise { then(cb: (value: BadPromise) => void): void; } +>then : (cb: (value: BadPromise) => void) => void +>cb : (value: BadPromise) => void +>value : BadPromise + +type T16 = Awaited; // error +>T16 : any + +interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; } +>then : (cb: (value: BadPromise2) => void) => void +>cb : (value: BadPromise2) => void +>value : BadPromise2 + +interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; } +>then : (cb: (value: BadPromise1) => void) => void +>cb : (value: BadPromise1) => void +>value : BadPromise1 + +type T17 = Awaited; // error +>T17 : any + +// https://github.com/microsoft/TypeScript/issues/33562 +type MaybePromise = T | Promise | PromiseLike +>MaybePromise : MaybePromise + +declare function MaybePromise(value: T): MaybePromise; +>MaybePromise : (value: T) => MaybePromise +>value : T + +async function main() { +>main : () => Promise + + let aaa: number; +>aaa : number + + let bbb: string; +>bbb : string + + [ +>[ aaa, bbb, ] = await Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : [number, string, boolean] +>[ aaa, bbb, ] : [number, string] + + aaa, +>aaa : number + + bbb, +>bbb : string + + ] = await Promise.all([ +>await Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : [number, string, boolean] +>Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : Promise<[number, string, boolean]> +>Promise.all : { (values: Iterable>): Promise; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>Promise : PromiseConstructor +>all : { (values: Iterable>): Promise; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>[ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ] : [number | Promise<1> | PromiseLike<1>, string | Promise<"2"> | PromiseLike<"2">, MaybePromise] + + MaybePromise(1), +>MaybePromise(1) : 1 | Promise<1> | PromiseLike<1> +>MaybePromise : (value: T) => MaybePromise +>1 : 1 + + MaybePromise('2'), +>MaybePromise('2') : "2" | Promise<"2"> | PromiseLike<"2"> +>MaybePromise : (value: T) => MaybePromise +>'2' : "2" + + MaybePromise(true), +>MaybePromise(true) : true | Promise | PromiseLike +>MaybePromise : (value: T) => MaybePromise +>true : true + + ]) +} + +// helps with tests where '.types' just prints out the type alias name +type _Expect = TActual; +>_Expect : TActual + diff --git a/tests/baselines/reference/awaitedTypeStrictNull.errors.txt b/tests/baselines/reference/awaitedTypeStrictNull.errors.txt new file mode 100644 index 0000000000000..aa2007e54e4b7 --- /dev/null +++ b/tests/baselines/reference/awaitedTypeStrictNull.errors.txt @@ -0,0 +1,52 @@ +tests/cases/compiler/awaitedTypeStrictNull.ts(18,12): error TS2589: Type instantiation is excessively deep and possibly infinite. +tests/cases/compiler/awaitedTypeStrictNull.ts(22,12): error TS2589: Type instantiation is excessively deep and possibly infinite. + + +==== tests/cases/compiler/awaitedTypeStrictNull.ts (2 errors) ==== + type T1 = Awaited; + type T2 = Awaited>; + type T3 = Awaited>; + type T4 = Awaited>; + type T5 = Awaited<{ then: number }>; + type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable") + type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable") + type T8 = Awaited<{ then(x: () => void): void }>; // unknown + type T9 = Awaited; + type T10 = Awaited; + type T11 = Awaited; + type T12 = Awaited>>; + type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful + type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful + type T15 = _Expect> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful + + interface BadPromise { then(cb: (value: BadPromise) => void): void; } + type T16 = Awaited; // error + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2589: Type instantiation is excessively deep and possibly infinite. + + interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; } + interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; } + type T17 = Awaited; // error + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2589: Type instantiation is excessively deep and possibly infinite. + + // https://github.com/microsoft/TypeScript/issues/33562 + type MaybePromise = T | Promise | PromiseLike + declare function MaybePromise(value: T): MaybePromise; + + async function main() { + let aaa: number; + let bbb: string; + [ + aaa, + bbb, + ] = await Promise.all([ + MaybePromise(1), + MaybePromise('2'), + MaybePromise(true), + ]) + } + + // helps with tests where '.types' just prints out the type alias name + type _Expect = TActual; + \ No newline at end of file diff --git a/tests/baselines/reference/awaitedTypeStrictNull.js b/tests/baselines/reference/awaitedTypeStrictNull.js new file mode 100644 index 0000000000000..82c1286111532 --- /dev/null +++ b/tests/baselines/reference/awaitedTypeStrictNull.js @@ -0,0 +1,58 @@ +//// [awaitedTypeStrictNull.ts] +type T1 = Awaited; +type T2 = Awaited>; +type T3 = Awaited>; +type T4 = Awaited>; +type T5 = Awaited<{ then: number }>; +type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable") +type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable") +type T8 = Awaited<{ then(x: () => void): void }>; // unknown +type T9 = Awaited; +type T10 = Awaited; +type T11 = Awaited; +type T12 = Awaited>>; +type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful +type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful +type T15 = _Expect> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful + +interface BadPromise { then(cb: (value: BadPromise) => void): void; } +type T16 = Awaited; // error + +interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; } +interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; } +type T17 = Awaited; // error + +// https://github.com/microsoft/TypeScript/issues/33562 +type MaybePromise = T | Promise | PromiseLike +declare function MaybePromise(value: T): MaybePromise; + +async function main() { + let aaa: number; + let bbb: string; + [ + aaa, + bbb, + ] = await Promise.all([ + MaybePromise(1), + MaybePromise('2'), + MaybePromise(true), + ]) +} + +// helps with tests where '.types' just prints out the type alias name +type _Expect = TActual; + + +//// [awaitedTypeStrictNull.js] +async function main() { + let aaa; + let bbb; + [ + aaa, + bbb, + ] = await Promise.all([ + MaybePromise(1), + MaybePromise('2'), + MaybePromise(true), + ]); +} diff --git a/tests/baselines/reference/awaitedTypeStrictNull.symbols b/tests/baselines/reference/awaitedTypeStrictNull.symbols new file mode 100644 index 0000000000000..d9ba7ffa85cca --- /dev/null +++ b/tests/baselines/reference/awaitedTypeStrictNull.symbols @@ -0,0 +1,171 @@ +=== tests/cases/compiler/awaitedTypeStrictNull.ts === +type T1 = Awaited; +>T1 : Symbol(T1, Decl(awaitedTypeStrictNull.ts, 0, 0)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T2 = Awaited>; +>T2 : Symbol(T2, Decl(awaitedTypeStrictNull.ts, 0, 26)) +>Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + +type T3 = Awaited>; +>T3 : Symbol(T3, Decl(awaitedTypeStrictNull.ts, 1, 35)) +>Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + +type T4 = Awaited>; +>T4 : Symbol(T4, Decl(awaitedTypeStrictNull.ts, 2, 44)) +>Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + +type T5 = Awaited<{ then: number }>; +>T5 : Symbol(T5, Decl(awaitedTypeStrictNull.ts, 3, 44)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedTypeStrictNull.ts, 4, 19)) + +type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable") +>T6 : Symbol(T6, Decl(awaitedTypeStrictNull.ts, 4, 36)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedTypeStrictNull.ts, 5, 19)) + +type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable") +>T7 : Symbol(T7, Decl(awaitedTypeStrictNull.ts, 5, 36)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedTypeStrictNull.ts, 6, 19)) +>x : Symbol(x, Decl(awaitedTypeStrictNull.ts, 6, 25)) + +type T8 = Awaited<{ then(x: () => void): void }>; // unknown +>T8 : Symbol(T8, Decl(awaitedTypeStrictNull.ts, 6, 45)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedTypeStrictNull.ts, 7, 19)) +>x : Symbol(x, Decl(awaitedTypeStrictNull.ts, 7, 25)) + +type T9 = Awaited; +>T9 : Symbol(T9, Decl(awaitedTypeStrictNull.ts, 7, 49)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T10 = Awaited; +>T10 : Symbol(T10, Decl(awaitedTypeStrictNull.ts, 8, 23)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T11 = Awaited; +>T11 : Symbol(T11, Decl(awaitedTypeStrictNull.ts, 9, 26)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T12 = Awaited>>; +>T12 : Symbol(T12, Decl(awaitedTypeStrictNull.ts, 10, 28)) +>Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + +type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful +>T13 : Symbol(T13, Decl(awaitedTypeStrictNull.ts, 11, 45)) +>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 38, 1)) +>Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + +type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful +>T14 : Symbol(T14, Decl(awaitedTypeStrictNull.ts, 12, 107)) +>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 38, 1)) +>Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + +type T15 = _Expect> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful +>T15 : Symbol(T15, Decl(awaitedTypeStrictNull.ts, 13, 117)) +>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 38, 1)) +>Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + +interface BadPromise { then(cb: (value: BadPromise) => void): void; } +>BadPromise : Symbol(BadPromise, Decl(awaitedTypeStrictNull.ts, 14, 131)) +>then : Symbol(BadPromise.then, Decl(awaitedTypeStrictNull.ts, 16, 22)) +>cb : Symbol(cb, Decl(awaitedTypeStrictNull.ts, 16, 28)) +>value : Symbol(value, Decl(awaitedTypeStrictNull.ts, 16, 33)) +>BadPromise : Symbol(BadPromise, Decl(awaitedTypeStrictNull.ts, 14, 131)) + +type T16 = Awaited; // error +>T16 : Symbol(T16, Decl(awaitedTypeStrictNull.ts, 16, 69)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>BadPromise : Symbol(BadPromise, Decl(awaitedTypeStrictNull.ts, 14, 131)) + +interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; } +>BadPromise1 : Symbol(BadPromise1, Decl(awaitedTypeStrictNull.ts, 17, 31)) +>then : Symbol(BadPromise1.then, Decl(awaitedTypeStrictNull.ts, 19, 23)) +>cb : Symbol(cb, Decl(awaitedTypeStrictNull.ts, 19, 29)) +>value : Symbol(value, Decl(awaitedTypeStrictNull.ts, 19, 34)) +>BadPromise2 : Symbol(BadPromise2, Decl(awaitedTypeStrictNull.ts, 19, 71)) + +interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; } +>BadPromise2 : Symbol(BadPromise2, Decl(awaitedTypeStrictNull.ts, 19, 71)) +>then : Symbol(BadPromise2.then, Decl(awaitedTypeStrictNull.ts, 20, 23)) +>cb : Symbol(cb, Decl(awaitedTypeStrictNull.ts, 20, 29)) +>value : Symbol(value, Decl(awaitedTypeStrictNull.ts, 20, 34)) +>BadPromise1 : Symbol(BadPromise1, Decl(awaitedTypeStrictNull.ts, 17, 31)) + +type T17 = Awaited; // error +>T17 : Symbol(T17, Decl(awaitedTypeStrictNull.ts, 20, 71)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>BadPromise1 : Symbol(BadPromise1, Decl(awaitedTypeStrictNull.ts, 17, 31)) + +// https://github.com/microsoft/TypeScript/issues/33562 +type MaybePromise = T | Promise | PromiseLike +>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32)) +>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 24, 18)) +>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 24, 18)) +>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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 24, 18)) +>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 24, 18)) + +declare function MaybePromise(value: T): MaybePromise; +>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32)) +>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 25, 30)) +>value : Symbol(value, Decl(awaitedTypeStrictNull.ts, 25, 33)) +>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 25, 30)) +>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32)) +>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 25, 30)) + +async function main() { +>main : Symbol(main, Decl(awaitedTypeStrictNull.ts, 25, 60)) + + let aaa: number; +>aaa : Symbol(aaa, Decl(awaitedTypeStrictNull.ts, 28, 7)) + + let bbb: string; +>bbb : Symbol(bbb, Decl(awaitedTypeStrictNull.ts, 29, 7)) + + [ + aaa, +>aaa : Symbol(aaa, Decl(awaitedTypeStrictNull.ts, 28, 7)) + + bbb, +>bbb : Symbol(bbb, Decl(awaitedTypeStrictNull.ts, 29, 7)) + + ] = await Promise.all([ +>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) +>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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) + + MaybePromise(1), +>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32)) + + MaybePromise('2'), +>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32)) + + MaybePromise(true), +>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32)) + + ]) +} + +// helps with tests where '.types' just prints out the type alias name +type _Expect = TActual; +>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 38, 1)) +>TActual : Symbol(TActual, Decl(awaitedTypeStrictNull.ts, 41, 13)) +>TExpected : Symbol(TExpected, Decl(awaitedTypeStrictNull.ts, 41, 39)) +>TExpected : Symbol(TExpected, Decl(awaitedTypeStrictNull.ts, 41, 39)) +>TActual : Symbol(TActual, Decl(awaitedTypeStrictNull.ts, 41, 13)) + diff --git a/tests/baselines/reference/awaitedTypeStrictNull.types b/tests/baselines/reference/awaitedTypeStrictNull.types new file mode 100644 index 0000000000000..53f170230aedd --- /dev/null +++ b/tests/baselines/reference/awaitedTypeStrictNull.types @@ -0,0 +1,134 @@ +=== tests/cases/compiler/awaitedTypeStrictNull.ts === +type T1 = Awaited; +>T1 : number + +type T2 = Awaited>; +>T2 : number + +type T3 = Awaited>; +>T3 : number + +type T4 = Awaited>; +>T4 : T4 + +type T5 = Awaited<{ then: number }>; +>T5 : { then: number; } +>then : number + +type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable") +>T6 : never +>then : () => void + +type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable") +>T7 : never +>then : (x: number) => void +>x : number + +type T8 = Awaited<{ then(x: () => void): void }>; // unknown +>T8 : unknown +>then : (x: () => void) => void +>x : () => void + +type T9 = Awaited; +>T9 : any + +type T10 = Awaited; +>T10 : never + +type T11 = Awaited; +>T11 : unknown + +type T12 = Awaited>>; +>T12 : number + +type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful +>T13 : string | number | null +>null : null +>null : null + +type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful +>T14 : string | number | undefined + +type T15 = _Expect> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful +>T15 : string | number | null | undefined +>null : null +>null : null + +interface BadPromise { then(cb: (value: BadPromise) => void): void; } +>then : (cb: (value: BadPromise) => void) => void +>cb : (value: BadPromise) => void +>value : BadPromise + +type T16 = Awaited; // error +>T16 : any + +interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; } +>then : (cb: (value: BadPromise2) => void) => void +>cb : (value: BadPromise2) => void +>value : BadPromise2 + +interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; } +>then : (cb: (value: BadPromise1) => void) => void +>cb : (value: BadPromise1) => void +>value : BadPromise1 + +type T17 = Awaited; // error +>T17 : any + +// https://github.com/microsoft/TypeScript/issues/33562 +type MaybePromise = T | Promise | PromiseLike +>MaybePromise : MaybePromise + +declare function MaybePromise(value: T): MaybePromise; +>MaybePromise : (value: T) => MaybePromise +>value : T + +async function main() { +>main : () => Promise + + let aaa: number; +>aaa : number + + let bbb: string; +>bbb : string + + [ +>[ aaa, bbb, ] = await Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : [number, string, boolean] +>[ aaa, bbb, ] : [number, string] + + aaa, +>aaa : number + + bbb, +>bbb : string + + ] = await Promise.all([ +>await Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : [number, string, boolean] +>Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : Promise<[number, string, boolean]> +>Promise.all : { (values: Iterable>): Promise; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>Promise : PromiseConstructor +>all : { (values: Iterable>): Promise; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>[ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ] : [number | Promise<1> | PromiseLike<1>, string | Promise<"2"> | PromiseLike<"2">, MaybePromise] + + MaybePromise(1), +>MaybePromise(1) : 1 | Promise<1> | PromiseLike<1> +>MaybePromise : (value: T) => MaybePromise +>1 : 1 + + MaybePromise('2'), +>MaybePromise('2') : "2" | Promise<"2"> | PromiseLike<"2"> +>MaybePromise : (value: T) => MaybePromise +>'2' : "2" + + MaybePromise(true), +>MaybePromise(true) : true | Promise | PromiseLike +>MaybePromise : (value: T) => MaybePromise +>true : true + + ]) +} + +// helps with tests where '.types' just prints out the type alias name +type _Expect = TActual; +>_Expect : TActual + diff --git a/tests/baselines/reference/correctOrderOfPromiseMethod.symbols b/tests/baselines/reference/correctOrderOfPromiseMethod.symbols index 29a494f4ec5c3..efd5ccc07b576 100644 --- a/tests/baselines/reference/correctOrderOfPromiseMethod.symbols +++ b/tests/baselines/reference/correctOrderOfPromiseMethod.symbols @@ -33,9 +33,9 @@ async function countEverything(): Promise { const [resultA, resultB] = await Promise.all([ >resultA : Symbol(resultA, Decl(correctOrderOfPromiseMethod.ts, 13, 11)) >resultB : Symbol(resultB, Decl(correctOrderOfPromiseMethod.ts, 13, 19)) ->Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 6 more) +>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) >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, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more) +>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) providerA(), >providerA : Symbol(providerA, Decl(correctOrderOfPromiseMethod.ts, 10, 9)) @@ -75,8 +75,8 @@ async function countEverything(): Promise { 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, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more) +>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) >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, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more) +>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) >undefined : Symbol(undefined) diff --git a/tests/baselines/reference/correctOrderOfPromiseMethod.types b/tests/baselines/reference/correctOrderOfPromiseMethod.types index fe38cd1dfbbf5..73ef72cb744ac 100644 --- a/tests/baselines/reference/correctOrderOfPromiseMethod.types +++ b/tests/baselines/reference/correctOrderOfPromiseMethod.types @@ -30,9 +30,9 @@ async function countEverything(): Promise { >resultB : B[] >await Promise.all([ providerA(), providerB(), ]) : [A[], B[]] >Promise.all([ providerA(), providerB(), ]) : Promise<[A[], B[]]> ->Promise.all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>Promise.all : { (values: Iterable>): Promise; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } >Promise : PromiseConstructor ->all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>all : { (values: Iterable>): Promise; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } >[ providerA(), providerB(), ] : [Promise, Promise] providerA(), @@ -76,9 +76,9 @@ async function countEverything(): Promise { 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: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>Promise.all : { (values: Iterable>): Promise; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } >Promise : PromiseConstructor ->all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>all : { (values: Iterable>): Promise; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } >undefined as readonly ["a", "b", "c"] : readonly ["a", "b", "c"] >undefined : undefined diff --git a/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.symbols b/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.symbols index ecf867a2bf715..8deaf8a246922 100644 --- a/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.symbols +++ b/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.symbols @@ -381,9 +381,9 @@ const f1: F = () => { >F : Symbol(F, Decl(inferFromGenericFunctionReturnTypes3.ts, 153, 2)) return Promise.all([ ->Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 6 more) +>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) >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, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more) +>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) { name: "David Gomes", >name : Symbol(name, Decl(inferFromGenericFunctionReturnTypes3.ts, 159, 9)) diff --git a/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types b/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types index 5ccfc66940c45..48a04b3d48298 100644 --- a/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types +++ b/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types @@ -409,14 +409,14 @@ type F = () => Promise>; const f1: F = () => { >f1 : F ->() => { return Promise.all([ { name: "David Gomes", age: 23, position: "GOALKEEPER", }, { name: "Cristiano Ronaldo", age: 33, position: "STRIKER", } ]);} : () => Promise<[{ name: string; age: number; position: "GOALKEEPER"; }, { name: string; age: number; position: "STRIKER"; }]> +>() => { return Promise.all([ { name: "David Gomes", age: 23, position: "GOALKEEPER", }, { name: "Cristiano Ronaldo", age: 33, position: "STRIKER", } ]);} : () => Promise<({ name: string; age: number; position: "GOALKEEPER"; } | { name: string; age: number; position: "STRIKER"; })[]> return Promise.all([ ->Promise.all([ { name: "David Gomes", age: 23, position: "GOALKEEPER", }, { name: "Cristiano Ronaldo", age: 33, position: "STRIKER", } ]) : Promise<[{ name: string; age: number; position: "GOALKEEPER"; }, { name: string; age: number; position: "STRIKER"; }]> ->Promise.all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>Promise.all([ { name: "David Gomes", age: 23, position: "GOALKEEPER", }, { name: "Cristiano Ronaldo", age: 33, position: "STRIKER", } ]) : Promise<({ name: string; age: number; position: "GOALKEEPER"; } | { name: string; age: number; position: "STRIKER"; })[]> +>Promise.all : { (values: Iterable>): Promise; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } >Promise : PromiseConstructor ->all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } ->[ { name: "David Gomes", age: 23, position: "GOALKEEPER", }, { name: "Cristiano Ronaldo", age: 33, position: "STRIKER", } ] : [{ name: string; age: number; position: "GOALKEEPER"; }, { name: string; age: number; position: "STRIKER"; }] +>all : { (values: Iterable>): Promise; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>[ { name: "David Gomes", age: 23, position: "GOALKEEPER", }, { name: "Cristiano Ronaldo", age: 33, position: "STRIKER", } ] : ({ name: string; age: number; position: "GOALKEEPER"; } | { name: string; age: number; position: "STRIKER"; })[] { >{ name: "David Gomes", age: 23, position: "GOALKEEPER", } : { name: string; age: number; position: "GOALKEEPER"; } diff --git a/tests/baselines/reference/inferenceLimit.symbols b/tests/baselines/reference/inferenceLimit.symbols index 4b7091a05857e..55cf1c34802e7 100644 --- a/tests/baselines/reference/inferenceLimit.symbols +++ b/tests/baselines/reference/inferenceLimit.symbols @@ -61,9 +61,9 @@ export class BrokenClass { return Promise.all(result.map(populateItems)) >Promise.all(result.map(populateItems)) .then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 6 more) +>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) >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, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more) +>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) >result.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) >result : Symbol(result, Decl(file1.ts, 10, 7)) >map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) diff --git a/tests/baselines/reference/inferenceLimit.types b/tests/baselines/reference/inferenceLimit.types index 48aa9aeec0236..094444a06698e 100644 --- a/tests/baselines/reference/inferenceLimit.types +++ b/tests/baselines/reference/inferenceLimit.types @@ -76,9 +76,9 @@ export class BrokenClass { >Promise.all(result.map(populateItems)) .then((orders: Array) => { resolve(orders); }) : Promise >Promise.all(result.map(populateItems)) .then : (onfulfilled?: (value: unknown[]) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise >Promise.all(result.map(populateItems)) : Promise ->Promise.all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>Promise.all : { (values: Iterable>): Promise; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } >Promise : PromiseConstructor ->all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>all : { (values: Iterable>): Promise; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } >result.map(populateItems) : Promise[] >result.map : (callbackfn: (value: MyModule.MyModel, index: number, array: MyModule.MyModel[]) => U, thisArg?: any) => U[] >result : MyModule.MyModel[] diff --git a/tests/baselines/reference/mappedTypesArraysTuples.js b/tests/baselines/reference/mappedTypesArraysTuples.js index 7bd4b03a6e54f..16459b6d6c262 100644 --- a/tests/baselines/reference/mappedTypesArraysTuples.js +++ b/tests/baselines/reference/mappedTypesArraysTuples.js @@ -58,8 +58,8 @@ let y21 = nonpartial(x21); declare let x22: { a: number | undefined, b?: string[] }; let y22 = nonpartial(x22); -type Awaited = T extends PromiseLike ? U : T; -type Awaitified = { [P in keyof T]: Awaited }; +type __Awaited = T extends PromiseLike ? U : T; +type Awaitified = { [P in keyof T]: __Awaited }; declare function all(...values: T): Promise>; @@ -189,9 +189,9 @@ declare let y22: { a: number; b: string[]; }; -declare type Awaited = T extends PromiseLike ? U : T; +declare type __Awaited = T extends PromiseLike ? U : T; declare type Awaitified = { - [P in keyof T]: Awaited; + [P in keyof T]: __Awaited; }; declare function all(...values: T): Promise>; declare function f1(a: number, b: Promise, c: string[], d: Promise): void; diff --git a/tests/baselines/reference/mappedTypesArraysTuples.symbols b/tests/baselines/reference/mappedTypesArraysTuples.symbols index 48a3979585c7e..ac3ec26462200 100644 --- a/tests/baselines/reference/mappedTypesArraysTuples.symbols +++ b/tests/baselines/reference/mappedTypesArraysTuples.symbols @@ -214,31 +214,31 @@ let y22 = nonpartial(x22); >nonpartial : Symbol(nonpartial, Decl(mappedTypesArraysTuples.ts, 46, 24)) >x22 : Symbol(x22, Decl(mappedTypesArraysTuples.ts, 56, 11)) -type Awaited = T extends PromiseLike ? U : T; ->Awaited : Symbol(Awaited, Decl(mappedTypesArraysTuples.ts, 57, 26)) ->T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 59, 13)) ->T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 59, 13)) +type __Awaited = T extends PromiseLike ? U : T; +>__Awaited : Symbol(__Awaited, Decl(mappedTypesArraysTuples.ts, 57, 26)) +>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 59, 15)) +>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 59, 15)) >PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --)) ->U : Symbol(U, Decl(mappedTypesArraysTuples.ts, 59, 45)) ->U : Symbol(U, Decl(mappedTypesArraysTuples.ts, 59, 45)) ->T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 59, 13)) +>U : Symbol(U, Decl(mappedTypesArraysTuples.ts, 59, 47)) +>U : Symbol(U, Decl(mappedTypesArraysTuples.ts, 59, 47)) +>T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 59, 15)) -type Awaitified = { [P in keyof T]: Awaited }; ->Awaitified : Symbol(Awaitified, Decl(mappedTypesArraysTuples.ts, 59, 57)) +type Awaitified = { [P in keyof T]: __Awaited }; +>Awaitified : Symbol(Awaitified, Decl(mappedTypesArraysTuples.ts, 59, 59)) >T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 60, 16)) >P : Symbol(P, Decl(mappedTypesArraysTuples.ts, 60, 24)) >T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 60, 16)) ->Awaited : Symbol(Awaited, Decl(mappedTypesArraysTuples.ts, 57, 26)) +>__Awaited : Symbol(__Awaited, Decl(mappedTypesArraysTuples.ts, 57, 26)) >T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 60, 16)) >P : Symbol(P, Decl(mappedTypesArraysTuples.ts, 60, 24)) declare function all(...values: T): Promise>; ->all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 55)) +>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 57)) >T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 62, 21)) >values : Symbol(values, Decl(mappedTypesArraysTuples.ts, 62, 38)) >T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 62, 21)) >Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --)) ->Awaitified : Symbol(Awaitified, Decl(mappedTypesArraysTuples.ts, 59, 57)) +>Awaitified : Symbol(Awaitified, Decl(mappedTypesArraysTuples.ts, 59, 59)) >T : Symbol(T, Decl(mappedTypesArraysTuples.ts, 62, 21)) function f1(a: number, b: Promise, c: string[], d: Promise) { @@ -252,25 +252,25 @@ function f1(a: number, b: Promise, c: string[], d: Promise) { let x1 = all(a); >x1 : Symbol(x1, Decl(mappedTypesArraysTuples.ts, 65, 7)) ->all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 55)) +>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 57)) >a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 64, 12)) let x2 = all(a, b); >x2 : Symbol(x2, Decl(mappedTypesArraysTuples.ts, 66, 7)) ->all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 55)) +>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 57)) >a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 64, 12)) >b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 64, 22)) let x3 = all(a, b, c); >x3 : Symbol(x3, Decl(mappedTypesArraysTuples.ts, 67, 7)) ->all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 55)) +>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 57)) >a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 64, 12)) >b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 64, 22)) >c : Symbol(c, Decl(mappedTypesArraysTuples.ts, 64, 42)) let x4 = all(a, b, c, d); >x4 : Symbol(x4, Decl(mappedTypesArraysTuples.ts, 68, 7)) ->all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 55)) +>all : Symbol(all, Decl(mappedTypesArraysTuples.ts, 60, 57)) >a : Symbol(a, Decl(mappedTypesArraysTuples.ts, 64, 12)) >b : Symbol(b, Decl(mappedTypesArraysTuples.ts, 64, 22)) >c : Symbol(c, Decl(mappedTypesArraysTuples.ts, 64, 42)) diff --git a/tests/baselines/reference/mappedTypesArraysTuples.types b/tests/baselines/reference/mappedTypesArraysTuples.types index daa27b7958d07..082890b009713 100644 --- a/tests/baselines/reference/mappedTypesArraysTuples.types +++ b/tests/baselines/reference/mappedTypesArraysTuples.types @@ -152,10 +152,10 @@ let y22 = nonpartial(x22); >nonpartial : (x: Partial) => T >x22 : { a: number | undefined; b?: string[] | undefined; } -type Awaited = T extends PromiseLike ? U : T; ->Awaited : Awaited +type __Awaited = T extends PromiseLike ? U : T; +>__Awaited : __Awaited -type Awaitified = { [P in keyof T]: Awaited }; +type Awaitified = { [P in keyof T]: __Awaited }; >Awaitified : Awaitified declare function all(...values: T): Promise>; diff --git a/tests/baselines/reference/recursiveConditionalTypes.errors.txt b/tests/baselines/reference/recursiveConditionalTypes.errors.txt index c1ea1ab3338ee..794df99a50606 100644 --- a/tests/baselines/reference/recursiveConditionalTypes.errors.txt +++ b/tests/baselines/reference/recursiveConditionalTypes.errors.txt @@ -1,10 +1,10 @@ tests/cases/compiler/recursiveConditionalTypes.ts(16,11): error TS2589: Type instantiation is excessively deep and possibly infinite. -tests/cases/compiler/recursiveConditionalTypes.ts(20,5): error TS2322: Type 'Awaited' is not assignable to type 'Awaited'. +tests/cases/compiler/recursiveConditionalTypes.ts(20,5): error TS2322: Type '__Awaited' is not assignable to type '__Awaited'. Type 'T' is not assignable to type 'U'. 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'. -tests/cases/compiler/recursiveConditionalTypes.ts(21,5): error TS2322: Type 'T' is not assignable to type 'Awaited'. -tests/cases/compiler/recursiveConditionalTypes.ts(22,5): error TS2322: Type 'Awaited' is not assignable to type 'T'. - 'T' could be instantiated with an arbitrary type which could be unrelated to 'Awaited'. +tests/cases/compiler/recursiveConditionalTypes.ts(21,5): error TS2322: Type 'T' is not assignable to type '__Awaited'. +tests/cases/compiler/recursiveConditionalTypes.ts(22,5): error TS2322: Type '__Awaited' is not assignable to type 'T'. + 'T' could be instantiated with an arbitrary type which could be unrelated to '__Awaited'. tests/cases/compiler/recursiveConditionalTypes.ts(35,11): error TS2589: Type instantiation is excessively deep and possibly infinite. tests/cases/compiler/recursiveConditionalTypes.ts(46,12): error TS2589: Type instantiation is excessively deep and possibly infinite. tests/cases/compiler/recursiveConditionalTypes.ts(49,5): error TS2322: Type 'TupleOf' is not assignable to type 'TupleOf'. @@ -28,9 +28,9 @@ tests/cases/compiler/recursiveConditionalTypes.ts(116,9): error TS2345: Argument ==== tests/cases/compiler/recursiveConditionalTypes.ts (9 errors) ==== // Awaiting promises - type Awaited = + type __Awaited = T extends null | undefined ? T : - T extends PromiseLike ? Awaited : + T extends PromiseLike ? __Awaited : T; type MyPromise = { @@ -39,26 +39,26 @@ tests/cases/compiler/recursiveConditionalTypes.ts(116,9): error TS2345: Argument type InfinitePromise = Promise>; - type P0 = Awaited | null> | undefined>>; - type P1 = Awaited; - type P2 = Awaited>; // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + type P0 = __Awaited | null> | undefined>>; + type P1 = __Awaited; + type P2 = __Awaited>; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2589: Type instantiation is excessively deep and possibly infinite. - function f11(tx: T, ta: Awaited, ux: U, ua: Awaited) { + function f11(tx: T, ta: __Awaited, ux: U, ua: __Awaited) { ta = ua; ua = ta; // Error ~~ -!!! error TS2322: Type 'Awaited' is not assignable to type 'Awaited'. +!!! error TS2322: Type '__Awaited' is not assignable to type '__Awaited'. !!! error TS2322: Type 'T' is not assignable to type 'U'. !!! error TS2322: 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'. ta = tx; // Error ~~ -!!! error TS2322: Type 'T' is not assignable to type 'Awaited'. +!!! error TS2322: Type 'T' is not assignable to type '__Awaited'. tx = ta; // Error ~~ -!!! error TS2322: Type 'Awaited' is not assignable to type 'T'. -!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Awaited'. +!!! error TS2322: Type '__Awaited' is not assignable to type 'T'. +!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to '__Awaited'. } // Flattening arrays diff --git a/tests/baselines/reference/recursiveConditionalTypes.js b/tests/baselines/reference/recursiveConditionalTypes.js index 4b908af402663..2b3bd623a7c3c 100644 --- a/tests/baselines/reference/recursiveConditionalTypes.js +++ b/tests/baselines/reference/recursiveConditionalTypes.js @@ -1,9 +1,9 @@ //// [recursiveConditionalTypes.ts] // Awaiting promises -type Awaited = +type __Awaited = T extends null | undefined ? T : - T extends PromiseLike ? Awaited : + T extends PromiseLike ? __Awaited : T; type MyPromise = { @@ -12,11 +12,11 @@ type MyPromise = { type InfinitePromise = Promise>; -type P0 = Awaited | null> | undefined>>; -type P1 = Awaited; -type P2 = Awaited>; // Error +type P0 = __Awaited | null> | undefined>>; +type P1 = __Awaited; +type P2 = __Awaited>; // Error -function f11(tx: T, ta: Awaited, ux: U, ua: Awaited) { +function f11(tx: T, ta: __Awaited, ux: U, ua: __Awaited) { ta = ua; ua = ta; // Error ta = tx; // Error @@ -171,15 +171,15 @@ function f21(x, y) { //// [recursiveConditionalTypes.d.ts] -declare type Awaited = T extends null | undefined ? T : T extends PromiseLike ? Awaited : T; +declare type __Awaited = T extends null | undefined ? T : T extends PromiseLike ? __Awaited : T; declare type MyPromise = { then(f: ((value: T) => U | PromiseLike) | null | undefined): MyPromise; }; declare type InfinitePromise = Promise>; -declare type P0 = Awaited | null> | undefined>>; -declare type P1 = Awaited; -declare type P2 = Awaited>; -declare function f11(tx: T, ta: Awaited, ux: U, ua: Awaited): void; +declare type P0 = __Awaited | null> | undefined>>; +declare type P1 = __Awaited; +declare type P2 = __Awaited>; +declare function f11(tx: T, ta: __Awaited, ux: U, ua: __Awaited): void; declare type Flatten = T extends unknown[] ? _Flatten[] : readonly _Flatten[]; declare type _Flatten = T extends readonly (infer U)[] ? _Flatten : T; declare type InfiniteArray = InfiniteArray[]; diff --git a/tests/baselines/reference/recursiveConditionalTypes.symbols b/tests/baselines/reference/recursiveConditionalTypes.symbols index 25cf1417b4039..6bc26009ee05c 100644 --- a/tests/baselines/reference/recursiveConditionalTypes.symbols +++ b/tests/baselines/reference/recursiveConditionalTypes.symbols @@ -1,23 +1,23 @@ === tests/cases/compiler/recursiveConditionalTypes.ts === // Awaiting promises -type Awaited = ->Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) ->T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 13)) +type __Awaited = +>__Awaited : Symbol(__Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) +>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 15)) T extends null | undefined ? T : ->T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 13)) ->T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 13)) +>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 15)) +>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 15)) - T extends PromiseLike ? Awaited : ->T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 13)) + T extends PromiseLike ? __Awaited : +>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 15)) >PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --)) >U : Symbol(U, Decl(recursiveConditionalTypes.ts, 4, 31)) ->Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) +>__Awaited : Symbol(__Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) >U : Symbol(U, Decl(recursiveConditionalTypes.ts, 4, 31)) T; ->T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 13)) +>T : Symbol(T, Decl(recursiveConditionalTypes.ts, 2, 15)) type MyPromise = { >MyPromise : Symbol(MyPromise, Decl(recursiveConditionalTypes.ts, 5, 6)) @@ -43,44 +43,44 @@ type InfinitePromise = Promise>; >InfinitePromise : Symbol(InfinitePromise, Decl(recursiveConditionalTypes.ts, 9, 1)) >T : Symbol(T, Decl(recursiveConditionalTypes.ts, 11, 21)) -type P0 = Awaited | null> | undefined>>; +type P0 = __Awaited | null> | undefined>>; >P0 : Symbol(P0, Decl(recursiveConditionalTypes.ts, 11, 54)) ->Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) +>__Awaited : Symbol(__Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) >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, --, --), Decl(lib.es2018.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) >MyPromise : Symbol(MyPromise, Decl(recursiveConditionalTypes.ts, 5, 6)) -type P1 = Awaited; ->P1 : Symbol(P1, Decl(recursiveConditionalTypes.ts, 13, 83)) ->Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) +type P1 = __Awaited; +>P1 : Symbol(P1, Decl(recursiveConditionalTypes.ts, 13, 85)) +>__Awaited : Symbol(__Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) -type P2 = Awaited>; // Error ->P2 : Symbol(P2, Decl(recursiveConditionalTypes.ts, 14, 23)) ->Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) +type P2 = __Awaited>; // Error +>P2 : Symbol(P2, Decl(recursiveConditionalTypes.ts, 14, 25)) +>__Awaited : Symbol(__Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) >InfinitePromise : Symbol(InfinitePromise, Decl(recursiveConditionalTypes.ts, 9, 1)) -function f11(tx: T, ta: Awaited, ux: U, ua: Awaited) { ->f11 : Symbol(f11, Decl(recursiveConditionalTypes.ts, 15, 43)) +function f11(tx: T, ta: __Awaited, ux: U, ua: __Awaited) { +>f11 : Symbol(f11, Decl(recursiveConditionalTypes.ts, 15, 45)) >T : Symbol(T, Decl(recursiveConditionalTypes.ts, 17, 13)) >U : Symbol(U, Decl(recursiveConditionalTypes.ts, 17, 15)) >T : Symbol(T, Decl(recursiveConditionalTypes.ts, 17, 13)) >tx : Symbol(tx, Decl(recursiveConditionalTypes.ts, 17, 29)) >T : Symbol(T, Decl(recursiveConditionalTypes.ts, 17, 13)) >ta : Symbol(ta, Decl(recursiveConditionalTypes.ts, 17, 35)) ->Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) +>__Awaited : Symbol(__Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) >T : Symbol(T, Decl(recursiveConditionalTypes.ts, 17, 13)) ->ux : Symbol(ux, Decl(recursiveConditionalTypes.ts, 17, 51)) +>ux : Symbol(ux, Decl(recursiveConditionalTypes.ts, 17, 53)) >U : Symbol(U, Decl(recursiveConditionalTypes.ts, 17, 15)) ->ua : Symbol(ua, Decl(recursiveConditionalTypes.ts, 17, 58)) ->Awaited : Symbol(Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) +>ua : Symbol(ua, Decl(recursiveConditionalTypes.ts, 17, 60)) +>__Awaited : Symbol(__Awaited, Decl(recursiveConditionalTypes.ts, 0, 0)) >U : Symbol(U, Decl(recursiveConditionalTypes.ts, 17, 15)) ta = ua; >ta : Symbol(ta, Decl(recursiveConditionalTypes.ts, 17, 35)) ->ua : Symbol(ua, Decl(recursiveConditionalTypes.ts, 17, 58)) +>ua : Symbol(ua, Decl(recursiveConditionalTypes.ts, 17, 60)) ua = ta; // Error ->ua : Symbol(ua, Decl(recursiveConditionalTypes.ts, 17, 58)) +>ua : Symbol(ua, Decl(recursiveConditionalTypes.ts, 17, 60)) >ta : Symbol(ta, Decl(recursiveConditionalTypes.ts, 17, 35)) ta = tx; // Error diff --git a/tests/baselines/reference/recursiveConditionalTypes.types b/tests/baselines/reference/recursiveConditionalTypes.types index 651799b01cfb8..dd014d5fb2a12 100644 --- a/tests/baselines/reference/recursiveConditionalTypes.types +++ b/tests/baselines/reference/recursiveConditionalTypes.types @@ -1,13 +1,13 @@ === tests/cases/compiler/recursiveConditionalTypes.ts === // Awaiting promises -type Awaited = ->Awaited : Awaited +type __Awaited = +>__Awaited : __Awaited T extends null | undefined ? T : >null : null - T extends PromiseLike ? Awaited : + T extends PromiseLike ? __Awaited : T; type MyPromise = { @@ -23,42 +23,42 @@ type MyPromise = { type InfinitePromise = Promise>; >InfinitePromise : InfinitePromise -type P0 = Awaited | null> | undefined>>; +type P0 = __Awaited | null> | undefined>>; >P0 : string | number | null | undefined >null : null -type P1 = Awaited; +type P1 = __Awaited; >P1 : any -type P2 = Awaited>; // Error +type P2 = __Awaited>; // Error >P2 : any -function f11(tx: T, ta: Awaited, ux: U, ua: Awaited) { ->f11 : (tx: T, ta: Awaited, ux: U, ua: Awaited) => void +function f11(tx: T, ta: __Awaited, ux: U, ua: __Awaited) { +>f11 : (tx: T, ta: __Awaited, ux: U, ua: __Awaited) => void >tx : T ->ta : Awaited +>ta : __Awaited >ux : U ->ua : Awaited +>ua : __Awaited ta = ua; ->ta = ua : Awaited ->ta : Awaited ->ua : Awaited +>ta = ua : __Awaited +>ta : __Awaited +>ua : __Awaited ua = ta; // Error ->ua = ta : Awaited ->ua : Awaited ->ta : Awaited +>ua = ta : __Awaited +>ua : __Awaited +>ta : __Awaited ta = tx; // Error >ta = tx : T ->ta : Awaited +>ta : __Awaited >tx : T tx = ta; // Error ->tx = ta : Awaited +>tx = ta : __Awaited >tx : T ->ta : Awaited +>ta : __Awaited } // Flattening arrays diff --git a/tests/cases/compiler/awaitedType.ts b/tests/cases/compiler/awaitedType.ts new file mode 100644 index 0000000000000..2a92edd930a2f --- /dev/null +++ b/tests/cases/compiler/awaitedType.ts @@ -0,0 +1,45 @@ +// @target: esnext +// @strictNullChecks: false + +type T1 = Awaited; +type T2 = Awaited>; +type T3 = Awaited>; +type T4 = Awaited>; +type T5 = Awaited<{ then: number }>; +type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable") +type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable") +type T8 = Awaited<{ then(x: () => void): void }>; // unknown +type T9 = Awaited; +type T10 = Awaited; +type T11 = Awaited; +type T12 = Awaited>>; +type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful +type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful +type T15 = _Expect> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful + +interface BadPromise { then(cb: (value: BadPromise) => void): void; } +type T16 = Awaited; // error + +interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; } +interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; } +type T17 = Awaited; // error + +// https://github.com/microsoft/TypeScript/issues/33562 +type MaybePromise = T | Promise | PromiseLike +declare function MaybePromise(value: T): MaybePromise; + +async function main() { + let aaa: number; + let bbb: string; + [ + aaa, + bbb, + ] = await Promise.all([ + MaybePromise(1), + MaybePromise('2'), + MaybePromise(true), + ]) +} + +// helps with tests where '.types' just prints out the type alias name +type _Expect = TActual; diff --git a/tests/cases/compiler/awaitedTypeStrictNull.ts b/tests/cases/compiler/awaitedTypeStrictNull.ts new file mode 100644 index 0000000000000..e5726653a5eb5 --- /dev/null +++ b/tests/cases/compiler/awaitedTypeStrictNull.ts @@ -0,0 +1,45 @@ +// @target: esnext +// @strictNullChecks: true + +type T1 = Awaited; +type T2 = Awaited>; +type T3 = Awaited>; +type T4 = Awaited>; +type T5 = Awaited<{ then: number }>; +type T6 = Awaited<{ then(): void }>; // never (non-promise "thenable") +type T7 = Awaited<{ then(x: number): void }>; // never (non-promise "thenable") +type T8 = Awaited<{ then(x: () => void): void }>; // unknown +type T9 = Awaited; +type T10 = Awaited; +type T11 = Awaited; +type T12 = Awaited>>; +type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful +type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful +type T15 = _Expect> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful + +interface BadPromise { then(cb: (value: BadPromise) => void): void; } +type T16 = Awaited; // error + +interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; } +interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; } +type T17 = Awaited; // error + +// https://github.com/microsoft/TypeScript/issues/33562 +type MaybePromise = T | Promise | PromiseLike +declare function MaybePromise(value: T): MaybePromise; + +async function main() { + let aaa: number; + let bbb: string; + [ + aaa, + bbb, + ] = await Promise.all([ + MaybePromise(1), + MaybePromise('2'), + MaybePromise(true), + ]) +} + +// helps with tests where '.types' just prints out the type alias name +type _Expect = TActual; diff --git a/tests/cases/compiler/recursiveConditionalTypes.ts b/tests/cases/compiler/recursiveConditionalTypes.ts index 5750abe0d5f58..935735a02e8ee 100644 --- a/tests/cases/compiler/recursiveConditionalTypes.ts +++ b/tests/cases/compiler/recursiveConditionalTypes.ts @@ -4,9 +4,9 @@ // Awaiting promises -type Awaited = +type __Awaited = T extends null | undefined ? T : - T extends PromiseLike ? Awaited : + T extends PromiseLike ? __Awaited : T; type MyPromise = { @@ -15,11 +15,11 @@ type MyPromise = { type InfinitePromise = Promise>; -type P0 = Awaited | null> | undefined>>; -type P1 = Awaited; -type P2 = Awaited>; // Error +type P0 = __Awaited | null> | undefined>>; +type P1 = __Awaited; +type P2 = __Awaited>; // Error -function f11(tx: T, ta: Awaited, ux: U, ua: Awaited) { +function f11(tx: T, ta: __Awaited, ux: U, ua: __Awaited) { ta = ua; ua = ta; // Error ta = tx; // Error diff --git a/tests/cases/conformance/types/mapped/mappedTypesArraysTuples.ts b/tests/cases/conformance/types/mapped/mappedTypesArraysTuples.ts index 2c0f7433ea31c..249d77974cba3 100644 --- a/tests/cases/conformance/types/mapped/mappedTypesArraysTuples.ts +++ b/tests/cases/conformance/types/mapped/mappedTypesArraysTuples.ts @@ -60,8 +60,8 @@ let y21 = nonpartial(x21); declare let x22: { a: number | undefined, b?: string[] }; let y22 = nonpartial(x22); -type Awaited = T extends PromiseLike ? U : T; -type Awaitified = { [P in keyof T]: Awaited }; +type __Awaited = T extends PromiseLike ? U : T; +type Awaitified = { [P in keyof T]: __Awaited }; declare function all(...values: T): Promise>; From 5bdae61bb2e19c0b489f9414ce3d7126ecf99833 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 2 Sep 2021 18:40:02 -0700 Subject: [PATCH 2/4] Use Awaited with 'await' --- src/compiler/checker.ts | 235 +++++++++++++----- src/lib/es5.d.ts | 12 +- ...syncArrowFunctionCapturesThis_es2017.types | 6 +- .../asyncArrowFunctionCapturesThis_es5.types | 6 +- .../asyncArrowFunctionCapturesThis_es6.types | 6 +- ...teAssignabilityToTypeParameters.errors.txt | 8 +- ...aborateAssignabilityToTypeParameters.types | 6 +- .../reference/forAwaitForUnion.types | 2 +- 8 files changed, 192 insertions(+), 89 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index de7c514576408..b17de17778e75 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -904,28 +904,29 @@ namespace ts { // and they will not get an error from not having unrelated library files let deferredGlobalESSymbolConstructorSymbol: Symbol | undefined; let deferredGlobalESSymbolConstructorTypeSymbol: Symbol | undefined; - let deferredGlobalESSymbolType: ObjectType; + let deferredGlobalESSymbolType: ObjectType | undefined; let deferredGlobalTypedPropertyDescriptorType: GenericType; - let deferredGlobalPromiseType: GenericType; - let deferredGlobalPromiseLikeType: GenericType; + let deferredGlobalPromiseType: GenericType | undefined; + let deferredGlobalPromiseLikeType: GenericType | undefined; let deferredGlobalPromiseConstructorSymbol: Symbol | undefined; - let deferredGlobalPromiseConstructorLikeType: ObjectType; - let deferredGlobalIterableType: GenericType; - let deferredGlobalIteratorType: GenericType; - let deferredGlobalIterableIteratorType: GenericType; - let deferredGlobalGeneratorType: GenericType; - let deferredGlobalIteratorYieldResultType: GenericType; - let deferredGlobalIteratorReturnResultType: GenericType; - let deferredGlobalAsyncIterableType: GenericType; - let deferredGlobalAsyncIteratorType: GenericType; - let deferredGlobalAsyncIterableIteratorType: GenericType; - let deferredGlobalAsyncGeneratorType: GenericType; - let deferredGlobalTemplateStringsArrayType: ObjectType; + let deferredGlobalPromiseConstructorLikeType: ObjectType | undefined; + let deferredGlobalIterableType: GenericType | undefined; + let deferredGlobalIteratorType: GenericType | undefined; + let deferredGlobalIterableIteratorType: GenericType | undefined; + let deferredGlobalGeneratorType: GenericType | undefined; + let deferredGlobalIteratorYieldResultType: GenericType | undefined; + let deferredGlobalIteratorReturnResultType: GenericType | undefined; + let deferredGlobalAsyncIterableType: GenericType | undefined; + let deferredGlobalAsyncIteratorType: GenericType | undefined; + let deferredGlobalAsyncIterableIteratorType: GenericType | undefined; + let deferredGlobalAsyncGeneratorType: GenericType | undefined; + let deferredGlobalTemplateStringsArrayType: ObjectType | undefined; let deferredGlobalImportMetaType: ObjectType; let deferredGlobalImportMetaExpressionType: ObjectType; - let deferredGlobalExtractSymbol: Symbol; - let deferredGlobalOmitSymbol: Symbol; - let deferredGlobalBigIntType: ObjectType; + let deferredGlobalExtractSymbol: Symbol | undefined; + let deferredGlobalOmitSymbol: Symbol | undefined; + let deferredGlobalAwaitedSymbol: Symbol | undefined; + let deferredGlobalBigIntType: ObjectType | undefined; const allPotentiallyUnusedIdentifiers = new Map(); // key is file name @@ -13320,28 +13321,48 @@ namespace ts { return getGlobalSymbol(name, SymbolFlags.Type, reportErrors ? Diagnostics.Cannot_find_global_type_0 : undefined); } + function getGlobalTypeAliasSymbol(name: __String, arity: number, reportErrors: boolean): Symbol | undefined { + const symbol = getGlobalSymbol(name, SymbolFlags.Type, reportErrors ? Diagnostics.Cannot_find_global_type_0 : undefined); + if (symbol) { + // Resolve the declared type of the symbol. This resolves type parameters for the type + // alias so that we can check arity. + getDeclaredTypeOfSymbol(symbol); + if (length(getSymbolLinks(symbol).typeParameters) !== arity) { + const decl = symbol.declarations && find(symbol.declarations, isTypeAliasDeclaration); + error(decl, Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbolName(symbol), arity); + return undefined; + } + } + return symbol; + } + function getGlobalSymbol(name: __String, meaning: SymbolFlags, diagnostic: DiagnosticMessage | undefined): Symbol | undefined { // Don't track references for global symbols anyway, so value if `isReference` is arbitrary return resolveName(undefined, name, meaning, diagnostic, name, /*isUse*/ false); } - function getGlobalType(name: __String, arity: 0, reportErrors: boolean): ObjectType; - function getGlobalType(name: __String, arity: number, reportErrors: boolean): GenericType; + function getGlobalType(name: __String, arity: 0, reportErrors: true): ObjectType; + function getGlobalType(name: __String, arity: 0, reportErrors: boolean): ObjectType | undefined; + function getGlobalType(name: __String, arity: number, reportErrors: true): GenericType; + function getGlobalType(name: __String, arity: number, reportErrors: boolean): GenericType | undefined; function getGlobalType(name: __String, arity: number, reportErrors: boolean): ObjectType | undefined { const symbol = getGlobalTypeSymbol(name, reportErrors); return symbol || reportErrors ? getTypeOfGlobalSymbol(symbol, arity) : undefined; } function getGlobalTypedPropertyDescriptorType() { - return deferredGlobalTypedPropertyDescriptorType || (deferredGlobalTypedPropertyDescriptorType = getGlobalType("TypedPropertyDescriptor" as __String, /*arity*/ 1, /*reportErrors*/ true)) || emptyGenericType; + // We always report an error, so store a result in the event we could not resolve the symbol to prevent reporting it multiple times + return deferredGlobalTypedPropertyDescriptorType ||= getGlobalType("TypedPropertyDescriptor" as __String, /*arity*/ 1, /*reportErrors*/ true) || emptyGenericType; } function getGlobalTemplateStringsArrayType() { - return deferredGlobalTemplateStringsArrayType || (deferredGlobalTemplateStringsArrayType = getGlobalType("TemplateStringsArray" as __String, /*arity*/ 0, /*reportErrors*/ true)) || emptyObjectType; + // We always report an error, so store a result in the event we could not resolve the symbol to prevent reporting it multiple times + return deferredGlobalTemplateStringsArrayType ||= getGlobalType("TemplateStringsArray" as __String, /*arity*/ 0, /*reportErrors*/ true) || emptyObjectType; } function getGlobalImportMetaType() { - return deferredGlobalImportMetaType || (deferredGlobalImportMetaType = getGlobalType("ImportMeta" as __String, /*arity*/ 0, /*reportErrors*/ true)) || emptyObjectType; + // We always report an error, so store a result in the event we could not resolve the symbol to prevent reporting it multiple times + return deferredGlobalImportMetaType ||= getGlobalType("ImportMeta" as __String, /*arity*/ 0, /*reportErrors*/ true) || emptyObjectType; } function getGlobalImportMetaExpressionType() { @@ -13362,72 +13383,72 @@ namespace ts { return deferredGlobalImportMetaExpressionType; } - function getGlobalESSymbolConstructorSymbol(reportErrors: boolean) { - return deferredGlobalESSymbolConstructorSymbol || (deferredGlobalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol" as __String, reportErrors)); + function getGlobalESSymbolConstructorSymbol(reportErrors: boolean): Symbol | undefined { + return deferredGlobalESSymbolConstructorSymbol ||= getGlobalValueSymbol("Symbol" as __String, reportErrors); } - function getGlobalESSymbolConstructorTypeSymbol(reportErrors: boolean) { - return deferredGlobalESSymbolConstructorTypeSymbol || (deferredGlobalESSymbolConstructorTypeSymbol = getGlobalTypeSymbol("SymbolConstructor" as __String, reportErrors)); + function getGlobalESSymbolConstructorTypeSymbol(reportErrors: boolean): Symbol | undefined { + return deferredGlobalESSymbolConstructorTypeSymbol ||= getGlobalTypeSymbol("SymbolConstructor" as __String, reportErrors); } function getGlobalESSymbolType(reportErrors: boolean) { - return deferredGlobalESSymbolType || (deferredGlobalESSymbolType = getGlobalType("Symbol" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType; + return (deferredGlobalESSymbolType ||= getGlobalType("Symbol" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType; } function getGlobalPromiseType(reportErrors: boolean) { - return deferredGlobalPromiseType || (deferredGlobalPromiseType = getGlobalType("Promise" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType; + return (deferredGlobalPromiseType ||= getGlobalType("Promise" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType; } function getGlobalPromiseLikeType(reportErrors: boolean) { - return deferredGlobalPromiseLikeType || (deferredGlobalPromiseLikeType = getGlobalType("PromiseLike" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType; + return (deferredGlobalPromiseLikeType ||= getGlobalType("PromiseLike" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType; } function getGlobalPromiseConstructorSymbol(reportErrors: boolean): Symbol | undefined { - return deferredGlobalPromiseConstructorSymbol || (deferredGlobalPromiseConstructorSymbol = getGlobalValueSymbol("Promise" as __String, reportErrors)); + return deferredGlobalPromiseConstructorSymbol ||= getGlobalValueSymbol("Promise" as __String, reportErrors); } function getGlobalPromiseConstructorLikeType(reportErrors: boolean) { - return deferredGlobalPromiseConstructorLikeType || (deferredGlobalPromiseConstructorLikeType = getGlobalType("PromiseConstructorLike" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType; + return (deferredGlobalPromiseConstructorLikeType ||= getGlobalType("PromiseConstructorLike" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType; } function getGlobalAsyncIterableType(reportErrors: boolean) { - return deferredGlobalAsyncIterableType || (deferredGlobalAsyncIterableType = getGlobalType("AsyncIterable" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType; + return (deferredGlobalAsyncIterableType ||= getGlobalType("AsyncIterable" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType; } function getGlobalAsyncIteratorType(reportErrors: boolean) { - return deferredGlobalAsyncIteratorType || (deferredGlobalAsyncIteratorType = getGlobalType("AsyncIterator" as __String, /*arity*/ 3, reportErrors)) || emptyGenericType; + return (deferredGlobalAsyncIteratorType ||= getGlobalType("AsyncIterator" as __String, /*arity*/ 3, reportErrors)) || emptyGenericType; } function getGlobalAsyncIterableIteratorType(reportErrors: boolean) { - return deferredGlobalAsyncIterableIteratorType || (deferredGlobalAsyncIterableIteratorType = getGlobalType("AsyncIterableIterator" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType; + return (deferredGlobalAsyncIterableIteratorType ||= getGlobalType("AsyncIterableIterator" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType; } function getGlobalAsyncGeneratorType(reportErrors: boolean) { - return deferredGlobalAsyncGeneratorType || (deferredGlobalAsyncGeneratorType = getGlobalType("AsyncGenerator" as __String, /*arity*/ 3, reportErrors)) || emptyGenericType; + return (deferredGlobalAsyncGeneratorType ||= getGlobalType("AsyncGenerator" as __String, /*arity*/ 3, reportErrors)) || emptyGenericType; } function getGlobalIterableType(reportErrors: boolean) { - return deferredGlobalIterableType || (deferredGlobalIterableType = getGlobalType("Iterable" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType; + return (deferredGlobalIterableType ||= getGlobalType("Iterable" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType; } function getGlobalIteratorType(reportErrors: boolean) { - return deferredGlobalIteratorType || (deferredGlobalIteratorType = getGlobalType("Iterator" as __String, /*arity*/ 3, reportErrors)) || emptyGenericType; + return (deferredGlobalIteratorType ||= getGlobalType("Iterator" as __String, /*arity*/ 3, reportErrors)) || emptyGenericType; } function getGlobalIterableIteratorType(reportErrors: boolean) { - return deferredGlobalIterableIteratorType || (deferredGlobalIterableIteratorType = getGlobalType("IterableIterator" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType; + return (deferredGlobalIterableIteratorType ||= getGlobalType("IterableIterator" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType; } function getGlobalGeneratorType(reportErrors: boolean) { - return deferredGlobalGeneratorType || (deferredGlobalGeneratorType = getGlobalType("Generator" as __String, /*arity*/ 3, reportErrors)) || emptyGenericType; + return (deferredGlobalGeneratorType ||= getGlobalType("Generator" as __String, /*arity*/ 3, reportErrors)) || emptyGenericType; } function getGlobalIteratorYieldResultType(reportErrors: boolean) { - return deferredGlobalIteratorYieldResultType || (deferredGlobalIteratorYieldResultType = getGlobalType("IteratorYieldResult" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType; + return (deferredGlobalIteratorYieldResultType ||= getGlobalType("IteratorYieldResult" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType; } function getGlobalIteratorReturnResultType(reportErrors: boolean) { - return deferredGlobalIteratorReturnResultType || (deferredGlobalIteratorReturnResultType = getGlobalType("IteratorReturnResult" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType; + return (deferredGlobalIteratorReturnResultType ||= getGlobalType("IteratorReturnResult" as __String, /*arity*/ 1, reportErrors)) || emptyGenericType; } function getGlobalTypeOrUndefined(name: __String, arity = 0): ObjectType | undefined { @@ -13435,16 +13456,27 @@ namespace ts { return symbol && getTypeOfGlobalSymbol(symbol, arity) as GenericType; } - function getGlobalExtractSymbol(): Symbol { - return deferredGlobalExtractSymbol || (deferredGlobalExtractSymbol = getGlobalSymbol("Extract" as __String, SymbolFlags.TypeAlias, Diagnostics.Cannot_find_global_type_0)!); // TODO: GH#18217 + function getGlobalExtractSymbol(): Symbol | undefined { + // We always report an error, so cache a result in the event we could not resolve the symbol to prevent reporting it multiple times + deferredGlobalExtractSymbol ||= getGlobalTypeAliasSymbol("Extract" as __String, /*arity*/ 2, /*reportErrors*/ true) || unknownSymbol; + return deferredGlobalExtractSymbol === unknownSymbol ? undefined : deferredGlobalExtractSymbol; } - function getGlobalOmitSymbol(): Symbol { - return deferredGlobalOmitSymbol || (deferredGlobalOmitSymbol = getGlobalSymbol("Omit" as __String, SymbolFlags.TypeAlias, Diagnostics.Cannot_find_global_type_0)!); // TODO: GH#18217 + function getGlobalOmitSymbol(): Symbol | undefined { + // We always report an error, so cache a result in the event we could not resolve the symbol to prevent reporting it multiple times + deferredGlobalOmitSymbol ||= getGlobalTypeAliasSymbol("Omit" as __String, /*arity*/ 2, /*reportErrors*/ true) || unknownSymbol; + return deferredGlobalOmitSymbol === unknownSymbol ? undefined : deferredGlobalOmitSymbol; + } + + function getGlobalAwaitedSymbol(reportErrors: boolean): Symbol | undefined { + if (reportErrors) debugger; + // Only cache `unknownSymbol` if we are reporting errors so that we don't report the error more than once. + deferredGlobalAwaitedSymbol ||= getGlobalTypeAliasSymbol("Awaited" as __String, /*arity*/ 1, reportErrors) || (reportErrors ? unknownSymbol : undefined); + return deferredGlobalAwaitedSymbol === unknownSymbol ? undefined : deferredGlobalAwaitedSymbol; } function getGlobalBigIntType(reportErrors: boolean) { - return deferredGlobalBigIntType || (deferredGlobalBigIntType = getGlobalType("BigInt" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType; + return (deferredGlobalBigIntType ||= getGlobalType("BigInt" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType; } /** @@ -25264,8 +25296,9 @@ namespace ts { } if (functionFlags & FunctionFlags.Async) { // Async function or AsyncGenerator function + // Get the awaited type without the `Awaited` alias const contextualAwaitedType = mapType(contextualReturnType, getAwaitedType); - return contextualAwaitedType && getUnionType([contextualAwaitedType, createPromiseLikeType(contextualAwaitedType)]); + return contextualAwaitedType && getUnionType([unwrapAwaitedType(contextualAwaitedType), createPromiseLikeType(contextualAwaitedType)]); } return contextualReturnType; // Regular function or Generator function @@ -25278,7 +25311,7 @@ namespace ts { const contextualType = getContextualType(node, contextFlags); if (contextualType) { const contextualAwaitedType = getAwaitedType(contextualType); - return contextualAwaitedType && getUnionType([contextualAwaitedType, createPromiseLikeType(contextualAwaitedType)]); + return contextualAwaitedType && getUnionType([unwrapAwaitedType(contextualAwaitedType), createPromiseLikeType(contextualAwaitedType)]); } return undefined; } @@ -32527,8 +32560,10 @@ namespace ts { let wouldWorkWithAwait = false; const errNode = errorNode || operatorToken; if (isRelated) { - const awaitedLeftType = getAwaitedType(leftType); - const awaitedRightType = getAwaitedType(rightType); + let awaitedLeftType = getAwaitedType(leftType); + let awaitedRightType = getAwaitedType(rightType); + awaitedLeftType &&= unwrapAwaitedType(awaitedLeftType); + awaitedRightType &&= unwrapAwaitedType(awaitedRightType); wouldWorkWithAwait = !(awaitedLeftType === leftType && awaitedRightType === rightType) && !!(awaitedLeftType && awaitedRightType) && isRelated(awaitedLeftType, awaitedRightType); @@ -34561,6 +34596,11 @@ namespace ts { return typeAsPromise.promisedTypeOfPromise = getTypeArguments(type as GenericType)[0]; } + // primitives with a `{ then() }` won't be unwrapped/adopted. + if (allTypesAssignableToKind(type, TypeFlags.Primitive | TypeFlags.Never)) { + return undefined; + } + const thenFunction = getTypeOfPropertyOfType(type, "then" as __String)!; // TODO: GH#18217 if (isTypeAny(thenFunction)) { return undefined; @@ -34610,6 +34650,54 @@ namespace ts { return !!thenFunction && getSignaturesOfType(getTypeWithFacts(thenFunction, TypeFacts.NEUndefinedOrNull), SignatureKind.Call).length > 0; } + interface AwaitedTypeInstantiation extends Type { + _awaitedTypeBrand: never; + aliasSymbol: Symbol; + aliasTypeArguments: readonly Type[]; + } + + function isAwaitedTypeInstantiation(type: Type): type is AwaitedTypeInstantiation { + if (type.flags & TypeFlags.Conditional) { + const awaitedSymbol = getGlobalAwaitedSymbol(/*reportErrors*/ false); + return !!awaitedSymbol && type.aliasSymbol === awaitedSymbol && type.aliasTypeArguments?.length === 1; + } + return false; + } + + /** + * For a generic `Awaited`, gets `T`. + */ + function unwrapAwaitedType(type: Type) { + return type.flags & TypeFlags.Union ? mapType(type, unwrapAwaitedType) : + isAwaitedTypeInstantiation(type) ? type.aliasTypeArguments[0] : + type; + } + + function createAwaitedTypeIfNeeded(type: Type): Type { + if (isTypeAny(type)) { + return type; + } + + // If this is already an `Awaited`, just return it. This helps to avoid `Awaited>` in higher-order. + if (isAwaitedTypeInstantiation(type)) { + return type; + } + + // Only instantiate `Awaited` if `T` contains possibly non-primitive types. + if (isGenericObjectType(type) && !allTypesAssignableToKind(type, TypeFlags.Primitive | TypeFlags.Never)) { + // Nothing to do if `Awaited` doesn't exist + const awaitedSymbol = getGlobalAwaitedSymbol(/*reportErrors*/ true); + if (awaitedSymbol) { + // Unwrap unions that may contain `Awaited`, otherwise its possible to manufacture an `Awaited | U>` where + // an `Awaited` would suffice. + return getTypeAliasInstantiation(awaitedSymbol, [unwrapAwaitedType(type)]); + } + } + + Debug.assert(getPromisedTypeOfPromise(type) === undefined, "type provided should not be a non-generic 'promise'-like."); + return type; + } + /** * Gets the "awaited type" of a type. * @@ -34625,21 +34713,28 @@ namespace ts { return type; } + // If this is already an `Awaited`, just return it. This avoids `Awaited>` in higher-order + if (isAwaitedTypeInstantiation(type)) { + return type; + } + + // If we've already cached an awaited type, return a possible `Awaited` for it. const typeAsAwaitable = type as PromiseOrAwaitableType; if (typeAsAwaitable.awaitedTypeOfType) { - return typeAsAwaitable.awaitedTypeOfType; + return createAwaitedTypeIfNeeded(typeAsAwaitable.awaitedTypeOfType); } // For a union, get a union of the awaited types of each constituent. - // - return typeAsAwaitable.awaitedTypeOfType = - mapType(type, errorNode ? constituentType => getAwaitedTypeWorker(constituentType, errorNode, diagnosticMessage, arg0) : getAwaitedTypeWorker); - } + if (type.flags & TypeFlags.Union) { + const mapper = errorNode ? (constituentType: Type) => getAwaitedType(constituentType, errorNode, diagnosticMessage, arg0) : getAwaitedType; + typeAsAwaitable.awaitedTypeOfType = mapType(type, mapper); + return typeAsAwaitable.awaitedTypeOfType && createAwaitedTypeIfNeeded(typeAsAwaitable.awaitedTypeOfType); + } - function getAwaitedTypeWorker(type: Type, errorNode?: Node, diagnosticMessage?: DiagnosticMessage, arg0?: string | number): Type | undefined { - const typeAsAwaitable = type as PromiseOrAwaitableType; - if (typeAsAwaitable.awaitedTypeOfType) { - return typeAsAwaitable.awaitedTypeOfType; + // primitives with a `{ then() }` won't be unwrapped/adopted. This prevents `Awaited` when `T extends string` + // (or another primitive), since the `Awaited` type only unwraps `object` types. + if (allTypesAssignableToKind(type, TypeFlags.Primitive | TypeFlags.Never)) { + return type; } const promisedType = getPromisedTypeOfPromise(type); @@ -34694,7 +34789,7 @@ namespace ts { return undefined; } - return typeAsAwaitable.awaitedTypeOfType = awaitedType; + return createAwaitedTypeIfNeeded(typeAsAwaitable.awaitedTypeOfType = awaitedType); } // The type was not a promise, so it could not be unwrapped any further. @@ -34714,13 +34809,13 @@ namespace ts { // be treated as a promise, they can cast to . if (isThenableType(type)) { if (errorNode) { - if (!diagnosticMessage) return Debug.fail(); + Debug.assertIsDefined(diagnosticMessage); error(errorNode, diagnosticMessage, arg0); } return undefined; } - return typeAsAwaitable.awaitedTypeOfType = type; + return createAwaitedTypeIfNeeded(typeAsAwaitable.awaitedTypeOfType = type); } /** @@ -34770,7 +34865,7 @@ namespace ts { if (globalPromiseType !== emptyGenericType && !isReferenceToType(returnType, globalPromiseType)) { // The promise type was not a valid type reference to the global promise type, so we // report an error and return the unknown type. - error(returnTypeNode, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type_Did_you_mean_to_write_Promise_0, typeToString(getAwaitedType(returnType) || voidType)); + error(returnTypeNode, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type_Did_you_mean_to_write_Promise_0, typeToString(unwrapAwaitedType(getAwaitedType(returnType) || voidType))); return; } } @@ -36641,6 +36736,10 @@ namespace ts { if (iterationTypes === noIterationTypes) return noIterationTypes; if (iterationTypes === anyIterationTypes) return anyIterationTypes; const { yieldType, returnType, nextType } = iterationTypes; + // if we're requesting diagnostics, report errors for a missing `Awaited`. + if (errorNode) { + getGlobalAwaitedSymbol(/*reportErrors*/ true); + } return createIterationTypes( getAwaitedType(yieldType, errorNode) || anyType, getAwaitedType(returnType, errorNode) || anyType, @@ -36667,7 +36766,9 @@ namespace ts { getIterationTypesOfIterableCached(type, asyncIterationTypesResolver) || getIterationTypesOfIterableFast(type, asyncIterationTypesResolver); if (iterationTypes) { - return iterationTypes; + return use & IterationUse.ForOfFlag ? + getAsyncFromSyncIterationTypes(iterationTypes, errorNode) : + iterationTypes; } } @@ -36756,7 +36857,7 @@ namespace ts { // While we define these as `any` and `undefined` in our libs by default, a custom lib *could* use // different definitions. const { returnType, nextType } = getIterationTypesOfGlobalIterableType(globalType, resolver); - return setCachedIterationTypes(type, resolver.iterableCacheKey, createIterationTypes(yieldType, returnType, nextType)); + return setCachedIterationTypes(type, resolver.iterableCacheKey, createIterationTypes(resolver.resolveIterationType(yieldType, /*errorNode*/ undefined) || yieldType, resolver.resolveIterationType(returnType, /*errorNode*/ undefined) || returnType, nextType)); } // As an optimization, if the type is an instantiation of the following global type, then @@ -37097,7 +37198,7 @@ namespace ts { const isGenerator = !!(functionFlags & FunctionFlags.Generator); const isAsync = !!(functionFlags & FunctionFlags.Async); return isGenerator ? getIterationTypeOfGeneratorFunctionReturnType(IterationTypeKind.Return, returnType, isAsync) ?? errorType : - isAsync ? getAwaitedType(returnType) ?? errorType : + isAsync ? unwrapAwaitedType(getAwaitedType(returnType) ?? errorType) : returnType; } diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index b7199804fb326..f546f2f0eb669 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1445,11 +1445,13 @@ interface Promise { */ type Awaited = T extends null | undefined ? T : // special case for `null | undefined` when not in `--noImplicitAny` mode - T extends { then(onfulfilled: infer F): any } ? // thenable, extracts the first argument to `then()` - F extends ((value: infer V) => any) ? // if the argument to `then` is callable, extracts the argument - Awaited : // recursively unwrap the value - never : // the argument to `then` was not callable. - T; // non-thenable + T extends object ? // `await` only unwraps object types with a callable then. Non-object types are not unwrapped. + T extends { then(onfulfilled: infer F): any } ? // thenable, extracts the first argument to `then()` + F extends ((value: infer V) => any) ? // if the argument to `then` is callable, extracts the argument + Awaited : // recursively unwrap the value + never : // the argument to `then` was not callable. + T : // argument was not an object + T; // non-thenable interface ArrayLike { readonly length: number; diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es2017.types b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es2017.types index 57f59302bb5bc..93e3136c139b5 100644 --- a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es2017.types +++ b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es2017.types @@ -6,9 +6,9 @@ class C { >method : () => void var fn = async () => await this; ->fn : () => Promise ->async () => await this : () => Promise ->await this : this +>fn : () => Promise> +>async () => await this : () => Promise> +>await this : Awaited >this : this } } diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.types b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.types index da378ee2718f9..90f89654c0518 100644 --- a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.types +++ b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.types @@ -6,9 +6,9 @@ class C { >method : () => void var fn = async () => await this; ->fn : () => Promise ->async () => await this : () => Promise ->await this : this +>fn : () => Promise> +>async () => await this : () => Promise> +>await this : Awaited >this : this } } diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es6.types b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es6.types index 5386a956ada9a..3b77fc642e4a2 100644 --- a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es6.types +++ b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es6.types @@ -6,9 +6,9 @@ class C { >method : () => void var fn = async () => await this; ->fn : () => Promise ->async () => await this : () => Promise ->await this : this +>fn : () => Promise> +>async () => await this : () => Promise> +>await this : Awaited >this : this } } diff --git a/tests/baselines/reference/doNotElaborateAssignabilityToTypeParameters.errors.txt b/tests/baselines/reference/doNotElaborateAssignabilityToTypeParameters.errors.txt index e01b5d483c9a5..f0297fe7552c0 100644 --- a/tests/baselines/reference/doNotElaborateAssignabilityToTypeParameters.errors.txt +++ b/tests/baselines/reference/doNotElaborateAssignabilityToTypeParameters.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/doNotElaborateAssignabilityToTypeParameters.ts(3,3): error TS2322: Type 'T | Yadda' is not assignable to type 'T'. - 'T' could be instantiated with an arbitrary type which could be unrelated to 'T | Yadda'. +tests/cases/compiler/doNotElaborateAssignabilityToTypeParameters.ts(3,3): error TS2322: Type 'Yadda | Awaited' is not assignable to type 'T'. + 'T' could be instantiated with an arbitrary type which could be unrelated to 'Yadda | Awaited'. ==== tests/cases/compiler/doNotElaborateAssignabilityToTypeParameters.ts (1 errors) ==== @@ -7,8 +7,8 @@ tests/cases/compiler/doNotElaborateAssignabilityToTypeParameters.ts(3,3): error let yaddable = await getXOrYadda(x); return yaddable; ~~~~~~~~~~~~~~~~ -!!! error TS2322: Type 'T | Yadda' is not assignable to type 'T'. -!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'T | Yadda'. +!!! error TS2322: Type 'Yadda | Awaited' is not assignable to type 'T'. +!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Yadda | Awaited'. } interface Yadda { diff --git a/tests/baselines/reference/doNotElaborateAssignabilityToTypeParameters.types b/tests/baselines/reference/doNotElaborateAssignabilityToTypeParameters.types index 52de160da5d7a..d401745bbc6c2 100644 --- a/tests/baselines/reference/doNotElaborateAssignabilityToTypeParameters.types +++ b/tests/baselines/reference/doNotElaborateAssignabilityToTypeParameters.types @@ -4,14 +4,14 @@ async function foo(x: T): Promise { >x : T let yaddable = await getXOrYadda(x); ->yaddable : T | Yadda ->await getXOrYadda(x) : T | Yadda +>yaddable : Yadda | Awaited +>await getXOrYadda(x) : Yadda | Awaited >getXOrYadda(x) : T | Yadda >getXOrYadda : (x: T) => T | Yadda >x : T return yaddable; ->yaddable : T | Yadda +>yaddable : Yadda | Awaited } interface Yadda { diff --git a/tests/baselines/reference/forAwaitForUnion.types b/tests/baselines/reference/forAwaitForUnion.types index 180197b26eafc..5598ebf233ea3 100644 --- a/tests/baselines/reference/forAwaitForUnion.types +++ b/tests/baselines/reference/forAwaitForUnion.types @@ -4,7 +4,7 @@ async function f(source: Iterable | AsyncIterable) { >source : Iterable | AsyncIterable for await (const x of source) { ->x : T +>x : Awaited >source : Iterable | AsyncIterable } } From 657f0a9d6bedbfd3897bebd0472f3a90662f25a5 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 3 Sep 2021 15:10:11 -0700 Subject: [PATCH 3/4] Clean up overloads --- src/lib/es2015.iterable.d.ts | 12 +-- src/lib/es2015.promise.d.ts | 88 ------------------- src/lib/es2020.promise.d.ts | 2 +- src/lib/es2021.promise.d.ts | 4 +- .../asyncArrowFunction9_es2017.errors.txt | 2 +- .../asyncArrowFunction9_es5.errors.txt | 2 +- .../asyncArrowFunction9_es6.errors.txt | 2 +- tests/baselines/reference/awaitedType.symbols | 4 +- tests/baselines/reference/awaitedType.types | 4 +- .../reference/awaitedTypeStrictNull.symbols | 4 +- .../reference/awaitedTypeStrictNull.types | 4 +- .../correctOrderOfPromiseMethod.symbols | 8 +- .../correctOrderOfPromiseMethod.types | 8 +- ...ferFromGenericFunctionReturnTypes3.symbols | 4 +- ...inferFromGenericFunctionReturnTypes3.types | 4 +- .../reference/inferenceLimit.symbols | 4 +- .../baselines/reference/inferenceLimit.types | 4 +- 17 files changed, 32 insertions(+), 128 deletions(-) diff --git a/src/lib/es2015.iterable.d.ts b/src/lib/es2015.iterable.d.ts index f8805a30eb239..20b6920e0d66e 100644 --- a/src/lib/es2015.iterable.d.ts +++ b/src/lib/es2015.iterable.d.ts @@ -203,7 +203,7 @@ interface PromiseConstructor { * @param values An iterable of Promises. * @returns A new Promise. */ - all(values: Iterable>): Promise; + all(values: Iterable>): Promise[]>; /** * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved @@ -211,15 +211,7 @@ interface PromiseConstructor { * @param values An iterable of Promises. * @returns A new Promise. */ - race(values: Iterable): Promise ? U : T>; - - /** - * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved - * or rejected. - * @param values An iterable of Promises. - * @returns A new Promise. - */ - race(values: Iterable>): Promise; + race(values: Iterable>): Promise>; } interface String { diff --git a/src/lib/es2015.promise.d.ts b/src/lib/es2015.promise.d.ts index e8c6ce477dde1..ac8f36de4b911 100644 --- a/src/lib/es2015.promise.d.ts +++ b/src/lib/es2015.promise.d.ts @@ -20,86 +20,6 @@ interface PromiseConstructor { */ all(values: T): Promise<{ -readonly [P in keyof T]: Awaited }>; - /** - * Creates a Promise that is resolved with an array of results when all of the provided Promises - * resolve, or rejected when any Promise is rejected. - * @param values An array of Promises. - * @returns A new Promise. - */ - all(values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; - - /** - * Creates a Promise that is resolved with an array of results when all of the provided Promises - * resolve, or rejected when any Promise is rejected. - * @param values An array of Promises. - * @returns A new Promise. - */ - all(values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; - - /** - * Creates a Promise that is resolved with an array of results when all of the provided Promises - * resolve, or rejected when any Promise is rejected. - * @param values An array of Promises. - * @returns A new Promise. - */ - all(values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; - - /** - * Creates a Promise that is resolved with an array of results when all of the provided Promises - * resolve, or rejected when any Promise is rejected. - * @param values An array of Promises. - * @returns A new Promise. - */ - all(values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; - - /** - * Creates a Promise that is resolved with an array of results when all of the provided Promises - * resolve, or rejected when any Promise is rejected. - * @param values An array of Promises. - * @returns A new Promise. - */ - all(values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; - - /** - * Creates a Promise that is resolved with an array of results when all of the provided Promises - * resolve, or rejected when any Promise is rejected. - * @param values An array of Promises. - * @returns A new Promise. - */ - all(values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; - - /** - * Creates a Promise that is resolved with an array of results when all of the provided Promises - * resolve, or rejected when any Promise is rejected. - * @param values An array of Promises. - * @returns A new Promise. - */ - all(values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; - - /** - * Creates a Promise that is resolved with an array of results when all of the provided Promises - * resolve, or rejected when any Promise is rejected. - * @param values An array of Promises. - * @returns A new Promise. - */ - all(values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; - - /** - * Creates a Promise that is resolved with an array of results when all of the provided Promises - * resolve, or rejected when any Promise is rejected. - * @param values An array of Promises. - * @returns A new Promise. - */ - all(values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; - - /** - * Creates a Promise that is resolved with an array of results when all of the provided Promises - * resolve, or rejected when any Promise is rejected. - * @param values An array of Promises. - * @returns A new Promise. - */ - all(values: readonly (T | PromiseLike)[]): Promise; - // see: lib.es2015.iterable.d.ts // all(values: Iterable>): Promise; @@ -111,14 +31,6 @@ interface PromiseConstructor { */ race(values: T): Promise>; - /** - * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved - * or rejected. - * @param values An array of Promises. - * @returns A new Promise. - */ - race(values: readonly T[]): Promise ? U : T>; - // see: lib.es2015.iterable.d.ts // race(values: Iterable): Promise ? U : T>; diff --git a/src/lib/es2020.promise.d.ts b/src/lib/es2020.promise.d.ts index f6dd5e4e65184..a1b408ff8f6a9 100644 --- a/src/lib/es2020.promise.d.ts +++ b/src/lib/es2020.promise.d.ts @@ -25,5 +25,5 @@ interface PromiseConstructor { * @param values An array of Promises. * @returns A new Promise. */ - allSettled(values: Iterable): Promise ? U : T>[]>; + allSettled(values: Iterable>): Promise>[]>; } diff --git a/src/lib/es2021.promise.d.ts b/src/lib/es2021.promise.d.ts index 4561908ebf584..ef9fdeda98389 100644 --- a/src/lib/es2021.promise.d.ts +++ b/src/lib/es2021.promise.d.ts @@ -19,12 +19,12 @@ interface PromiseConstructor { * @param values An array or iterable of Promises. * @returns A new Promise. */ - any(values: T): Promise>; + any(values: T): Promise>; /** * The any function returns a promise that is fulfilled by the first given promise to be fulfilled, or rejected with an AggregateError containing an array of rejection reasons if all of the given promises are rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm. * @param values An array or iterable of Promises. * @returns A new Promise. */ - any(values: (T | PromiseLike)[] | Iterable>): Promise + any(values: Iterable>): Promise> } diff --git a/tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt b/tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt index ed8dacf90fccd..7088e40bae2c0 100644 --- a/tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt +++ b/tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt @@ -16,7 +16,7 @@ tests/cases/conformance/async/es2017/asyncArrowFunction/asyncArrowFunction9_es20 !!! error TS1005: ',' expected. ~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'. -!!! related TS6203 /.ts/lib.es2015.promise.d.ts:166:13: 'Promise' was also declared here. +!!! related TS6203 /.ts/lib.es2015.promise.d.ts:78:13: 'Promise' was also declared here. ~ !!! error TS1005: ',' expected. ~~ diff --git a/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt b/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt index 4df3d4b80f83a..bd89949dbc1f8 100644 --- a/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt +++ b/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt @@ -16,7 +16,7 @@ tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts( !!! error TS1005: ',' expected. ~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'. -!!! related TS6203 /.ts/lib.es2015.promise.d.ts:166:13: 'Promise' was also declared here. +!!! related TS6203 /.ts/lib.es2015.promise.d.ts:78:13: 'Promise' was also declared here. ~ !!! error TS1005: ',' expected. ~~ diff --git a/tests/baselines/reference/asyncArrowFunction9_es6.errors.txt b/tests/baselines/reference/asyncArrowFunction9_es6.errors.txt index b84f6692e0d67..3335bebfa817c 100644 --- a/tests/baselines/reference/asyncArrowFunction9_es6.errors.txt +++ b/tests/baselines/reference/asyncArrowFunction9_es6.errors.txt @@ -16,7 +16,7 @@ tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts( !!! error TS1005: ',' expected. ~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'. -!!! related TS6203 /.ts/lib.es2015.promise.d.ts:166:13: 'Promise' was also declared here. +!!! related TS6203 /.ts/lib.es2015.promise.d.ts:78:13: 'Promise' was also declared here. ~ !!! error TS1005: ',' expected. ~~ diff --git a/tests/baselines/reference/awaitedType.symbols b/tests/baselines/reference/awaitedType.symbols index 635dc89f2c6f5..af4347bc1bc59 100644 --- a/tests/baselines/reference/awaitedType.symbols +++ b/tests/baselines/reference/awaitedType.symbols @@ -145,9 +145,9 @@ async function main() { >bbb : Symbol(bbb, Decl(awaitedType.ts, 29, 7)) ] = await Promise.all([ ->Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) +>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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) ->all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) +>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) MaybePromise(1), >MaybePromise : Symbol(MaybePromise, Decl(awaitedType.ts, 24, 54), Decl(awaitedType.ts, 21, 32)) diff --git a/tests/baselines/reference/awaitedType.types b/tests/baselines/reference/awaitedType.types index 56757e19e9bf4..0da35c5532eab 100644 --- a/tests/baselines/reference/awaitedType.types +++ b/tests/baselines/reference/awaitedType.types @@ -105,9 +105,9 @@ async function main() { ] = await Promise.all([ >await Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : [number, string, boolean] >Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : Promise<[number, string, boolean]> ->Promise.all : { (values: Iterable>): Promise; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>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; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>all : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } >[ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ] : [number | Promise<1> | PromiseLike<1>, string | Promise<"2"> | PromiseLike<"2">, MaybePromise] MaybePromise(1), diff --git a/tests/baselines/reference/awaitedTypeStrictNull.symbols b/tests/baselines/reference/awaitedTypeStrictNull.symbols index d9ba7ffa85cca..b928a63fe6bd5 100644 --- a/tests/baselines/reference/awaitedTypeStrictNull.symbols +++ b/tests/baselines/reference/awaitedTypeStrictNull.symbols @@ -145,9 +145,9 @@ async function main() { >bbb : Symbol(bbb, Decl(awaitedTypeStrictNull.ts, 29, 7)) ] = await Promise.all([ ->Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) +>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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) ->all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) +>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) MaybePromise(1), >MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32)) diff --git a/tests/baselines/reference/awaitedTypeStrictNull.types b/tests/baselines/reference/awaitedTypeStrictNull.types index 53f170230aedd..18312dda7c8e4 100644 --- a/tests/baselines/reference/awaitedTypeStrictNull.types +++ b/tests/baselines/reference/awaitedTypeStrictNull.types @@ -105,9 +105,9 @@ async function main() { ] = await Promise.all([ >await Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : [number, string, boolean] >Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : Promise<[number, string, boolean]> ->Promise.all : { (values: Iterable>): Promise; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>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; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>all : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } >[ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ] : [number | Promise<1> | PromiseLike<1>, string | Promise<"2"> | PromiseLike<"2">, MaybePromise] MaybePromise(1), diff --git a/tests/baselines/reference/correctOrderOfPromiseMethod.symbols b/tests/baselines/reference/correctOrderOfPromiseMethod.symbols index efd5ccc07b576..6efd2fdd69fc8 100644 --- a/tests/baselines/reference/correctOrderOfPromiseMethod.symbols +++ b/tests/baselines/reference/correctOrderOfPromiseMethod.symbols @@ -33,9 +33,9 @@ async function countEverything(): Promise { const [resultA, resultB] = await Promise.all([ >resultA : Symbol(resultA, Decl(correctOrderOfPromiseMethod.ts, 13, 11)) >resultB : Symbol(resultB, Decl(correctOrderOfPromiseMethod.ts, 13, 19)) ->Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) +>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, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 7 more) +>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) providerA(), >providerA : Symbol(providerA, Decl(correctOrderOfPromiseMethod.ts, 10, 9)) @@ -75,8 +75,8 @@ async function countEverything(): Promise { 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, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 7 more) +>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, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 7 more) +>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 73ef72cb744ac..8044cf7350268 100644 --- a/tests/baselines/reference/correctOrderOfPromiseMethod.types +++ b/tests/baselines/reference/correctOrderOfPromiseMethod.types @@ -30,9 +30,9 @@ async function countEverything(): Promise { >resultB : 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; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>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; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>all : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } >[ providerA(), providerB(), ] : [Promise, Promise] providerA(), @@ -76,9 +76,9 @@ async function countEverything(): Promise { 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; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>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; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>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/inferFromGenericFunctionReturnTypes3.symbols b/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.symbols index 8deaf8a246922..099c5761978d6 100644 --- a/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.symbols +++ b/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.symbols @@ -381,9 +381,9 @@ const f1: F = () => { >F : Symbol(F, Decl(inferFromGenericFunctionReturnTypes3.ts, 153, 2)) return Promise.all([ ->Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) +>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, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 7 more) +>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) { name: "David Gomes", >name : Symbol(name, Decl(inferFromGenericFunctionReturnTypes3.ts, 159, 9)) diff --git a/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types b/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types index 48a04b3d48298..bd2164e99e1d6 100644 --- a/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types +++ b/tests/baselines/reference/inferFromGenericFunctionReturnTypes3.types @@ -413,9 +413,9 @@ const f1: F = () => { return Promise.all([ >Promise.all([ { name: "David Gomes", age: 23, position: "GOALKEEPER", }, { name: "Cristiano Ronaldo", age: 33, position: "STRIKER", } ]) : Promise<({ name: string; age: number; position: "GOALKEEPER"; } | { name: string; age: number; position: "STRIKER"; })[]> ->Promise.all : { (values: Iterable>): Promise; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>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; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>all : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } >[ { name: "David Gomes", age: 23, position: "GOALKEEPER", }, { name: "Cristiano Ronaldo", age: 33, position: "STRIKER", } ] : ({ name: string; age: number; position: "GOALKEEPER"; } | { name: string; age: number; position: "STRIKER"; })[] { >{ name: "David Gomes", age: 23, position: "GOALKEEPER", } : { name: string; age: number; position: "GOALKEEPER"; } diff --git a/tests/baselines/reference/inferenceLimit.symbols b/tests/baselines/reference/inferenceLimit.symbols index 55cf1c34802e7..2c2a43c35bb52 100644 --- a/tests/baselines/reference/inferenceLimit.symbols +++ b/tests/baselines/reference/inferenceLimit.symbols @@ -61,9 +61,9 @@ export class BrokenClass { return Promise.all(result.map(populateItems)) >Promise.all(result.map(populateItems)) .then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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, --, --) ... and 7 more) +>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, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 7 more) +>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) >result.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) >result : Symbol(result, Decl(file1.ts, 10, 7)) >map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) diff --git a/tests/baselines/reference/inferenceLimit.types b/tests/baselines/reference/inferenceLimit.types index 094444a06698e..aa49bdd73b77a 100644 --- a/tests/baselines/reference/inferenceLimit.types +++ b/tests/baselines/reference/inferenceLimit.types @@ -76,9 +76,9 @@ export class BrokenClass { >Promise.all(result.map(populateItems)) .then((orders: Array) => { resolve(orders); }) : Promise >Promise.all(result.map(populateItems)) .then : (onfulfilled?: (value: unknown[]) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise >Promise.all(result.map(populateItems)) : Promise ->Promise.all : { (values: Iterable>): Promise; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>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; }>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>all : { (values: Iterable>): Promise[]>; (values: T): Promise<{ -readonly [P in keyof T]: Awaited; }>; } >result.map(populateItems) : Promise[] >result.map : (callbackfn: (value: MyModule.MyModel, index: number, array: MyModule.MyModel[]) => U, thisArg?: any) => U[] >result : MyModule.MyModel[] From d83915c0cdd51cd08ca8d65f37bdea68d45c3415 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 8 Sep 2021 16:47:13 -0700 Subject: [PATCH 4/4] Further restrict 'Awaited' auto-wrapping for 'await' --- src/compiler/checker.ts | 60 +++-- src/lib/es5.d.ts | 2 +- ...syncArrowFunctionCapturesThis_es2017.types | 6 +- .../asyncArrowFunctionCapturesThis_es5.types | 6 +- .../asyncArrowFunctionCapturesThis_es6.types | 6 +- .../reference/awaitedType.errors.txt | 116 +++++++++ tests/baselines/reference/awaitedType.js | 204 +++++++++++++++ tests/baselines/reference/awaitedType.symbols | 241 +++++++++++++++++- tests/baselines/reference/awaitedType.types | 218 ++++++++++++++++ tests/cases/compiler/awaitedType.ts | 116 +++++++++ 10 files changed, 933 insertions(+), 42 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b17de17778e75..92490cbccd9ab 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13469,7 +13469,6 @@ namespace ts { } function getGlobalAwaitedSymbol(reportErrors: boolean): Symbol | undefined { - if (reportErrors) debugger; // Only cache `unknownSymbol` if we are reporting errors so that we don't report the error more than once. deferredGlobalAwaitedSymbol ||= getGlobalTypeAliasSymbol("Awaited" as __String, /*arity*/ 1, reportErrors) || (reportErrors ? unknownSymbol : undefined); return deferredGlobalAwaitedSymbol === unknownSymbol ? undefined : deferredGlobalAwaitedSymbol; @@ -32560,10 +32559,8 @@ namespace ts { let wouldWorkWithAwait = false; const errNode = errorNode || operatorToken; if (isRelated) { - let awaitedLeftType = getAwaitedType(leftType); - let awaitedRightType = getAwaitedType(rightType); - awaitedLeftType &&= unwrapAwaitedType(awaitedLeftType); - awaitedRightType &&= unwrapAwaitedType(awaitedRightType); + const awaitedLeftType = unwrapAwaitedType(getAwaitedType(leftType)); + const awaitedRightType = unwrapAwaitedType(getAwaitedType(rightType)); wouldWorkWithAwait = !(awaitedLeftType === leftType && awaitedRightType === rightType) && !!(awaitedLeftType && awaitedRightType) && isRelated(awaitedLeftType, awaitedRightType); @@ -34643,9 +34640,14 @@ namespace ts { } /** - * Determines whether a type has a callable `then` member. + * Determines whether a type is an object with a callable `then` member. */ function isThenableType(type: Type): boolean { + if (allTypesAssignableToKind(type, TypeFlags.Primitive | TypeFlags.Never)) { + // primitive types cannot be considered "thenable" since they are not objects. + return false; + } + const thenFunction = getTypeOfPropertyOfType(type, "then" as __String); return !!thenFunction && getSignaturesOfType(getTypeWithFacts(thenFunction, TypeFacts.NEUndefinedOrNull), SignatureKind.Call).length > 0; } @@ -34667,13 +34669,24 @@ namespace ts { /** * For a generic `Awaited`, gets `T`. */ - function unwrapAwaitedType(type: Type) { + function unwrapAwaitedType(type: Type): Type; + function unwrapAwaitedType(type: Type | undefined): Type | undefined; + function unwrapAwaitedType(type: Type | undefined) { + if (!type) return undefined; return type.flags & TypeFlags.Union ? mapType(type, unwrapAwaitedType) : isAwaitedTypeInstantiation(type) ? type.aliasTypeArguments[0] : type; } function createAwaitedTypeIfNeeded(type: Type): Type { + // We wrap type `T` in `Awaited` based on the following conditions: + // - `T` is not already an `Awaited`, and + // - `T` is generic, and + // - One of the following applies: + // - `T` has no base constraint, or + // - The base constraint of `T` is `any`, `unknown`, `object`, or `{}`, or + // - The base constraint of `T` is an object type with a callable `then` method. + if (isTypeAny(type)) { return type; } @@ -34684,13 +34697,18 @@ namespace ts { } // Only instantiate `Awaited` if `T` contains possibly non-primitive types. - if (isGenericObjectType(type) && !allTypesAssignableToKind(type, TypeFlags.Primitive | TypeFlags.Never)) { - // Nothing to do if `Awaited` doesn't exist - const awaitedSymbol = getGlobalAwaitedSymbol(/*reportErrors*/ true); - if (awaitedSymbol) { - // Unwrap unions that may contain `Awaited`, otherwise its possible to manufacture an `Awaited | U>` where - // an `Awaited` would suffice. - return getTypeAliasInstantiation(awaitedSymbol, [unwrapAwaitedType(type)]); + if (isGenericObjectType(type)) { + const baseConstraint = getBaseConstraintOfType(type); + // Only instantiate `Awaited` if `T` has no base constraint, or the base constraint of `T` is `any`, `unknown`, `{}`, `object`, + // or is promise-like. + if (!baseConstraint || (baseConstraint.flags & TypeFlags.AnyOrUnknown) || isEmptyObjectType(baseConstraint) || isThenableType(baseConstraint)) { + // Nothing to do if `Awaited` doesn't exist + const awaitedSymbol = getGlobalAwaitedSymbol(/*reportErrors*/ true); + if (awaitedSymbol) { + // Unwrap unions that may contain `Awaited`, otherwise its possible to manufacture an `Awaited | U>` where + // an `Awaited` would suffice. + return getTypeAliasInstantiation(awaitedSymbol, [unwrapAwaitedType(type)]); + } } } @@ -34731,12 +34749,6 @@ namespace ts { return typeAsAwaitable.awaitedTypeOfType && createAwaitedTypeIfNeeded(typeAsAwaitable.awaitedTypeOfType); } - // primitives with a `{ then() }` won't be unwrapped/adopted. This prevents `Awaited` when `T extends string` - // (or another primitive), since the `Awaited` type only unwraps `object` types. - if (allTypesAssignableToKind(type, TypeFlags.Primitive | TypeFlags.Never)) { - return type; - } - const promisedType = getPromisedTypeOfPromise(type); if (promisedType) { if (type.id === promisedType.id || awaitedTypeStack.lastIndexOf(promisedType.id) >= 0) { @@ -34865,7 +34877,7 @@ namespace ts { if (globalPromiseType !== emptyGenericType && !isReferenceToType(returnType, globalPromiseType)) { // The promise type was not a valid type reference to the global promise type, so we // report an error and return the unknown type. - error(returnTypeNode, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type_Did_you_mean_to_write_Promise_0, typeToString(unwrapAwaitedType(getAwaitedType(returnType) || voidType))); + error(returnTypeNode, Diagnostics.The_return_type_of_an_async_function_or_method_must_be_the_global_Promise_T_type_Did_you_mean_to_write_Promise_0, typeToString(unwrapAwaitedType(getAwaitedType(returnType)) || voidType)); return; } } @@ -36865,7 +36877,7 @@ namespace ts { // - `Generator` or `AsyncGenerator` if (isReferenceToType(type, resolver.getGlobalGeneratorType(/*reportErrors*/ false))) { const [yieldType, returnType, nextType] = getTypeArguments(type as GenericType); - return setCachedIterationTypes(type, resolver.iterableCacheKey, createIterationTypes(yieldType, returnType, nextType)); + return setCachedIterationTypes(type, resolver.iterableCacheKey, createIterationTypes(resolver.resolveIterationType(yieldType, /*errorNode*/ undefined) || yieldType, resolver.resolveIterationType(returnType, /*errorNode*/ undefined) || returnType, nextType)); } } @@ -37197,8 +37209,8 @@ namespace ts { function unwrapReturnType(returnType: Type, functionFlags: FunctionFlags) { const isGenerator = !!(functionFlags & FunctionFlags.Generator); const isAsync = !!(functionFlags & FunctionFlags.Async); - return isGenerator ? getIterationTypeOfGeneratorFunctionReturnType(IterationTypeKind.Return, returnType, isAsync) ?? errorType : - isAsync ? unwrapAwaitedType(getAwaitedType(returnType) ?? errorType) : + return isGenerator ? getIterationTypeOfGeneratorFunctionReturnType(IterationTypeKind.Return, returnType, isAsync) || errorType : + isAsync ? unwrapAwaitedType(getAwaitedType(returnType)) || errorType : returnType; } diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index f546f2f0eb669..6d98cd4b96ef0 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1444,7 +1444,7 @@ interface Promise { * Recursively unwraps the "awaited type" of a type. Non-promise "thenables" should resolve to `never`. This emulates the behavior of `await`. */ type Awaited = - T extends null | undefined ? T : // special case for `null | undefined` when not in `--noImplicitAny` mode + T extends null | undefined ? T : // special case for `null | undefined` when not in `--strictNullChecks` mode T extends object ? // `await` only unwraps object types with a callable then. Non-object types are not unwrapped. T extends { then(onfulfilled: infer F): any } ? // thenable, extracts the first argument to `then()` F extends ((value: infer V) => any) ? // if the argument to `then` is callable, extracts the argument diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es2017.types b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es2017.types index 93e3136c139b5..57f59302bb5bc 100644 --- a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es2017.types +++ b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es2017.types @@ -6,9 +6,9 @@ class C { >method : () => void var fn = async () => await this; ->fn : () => Promise> ->async () => await this : () => Promise> ->await this : Awaited +>fn : () => Promise +>async () => await this : () => Promise +>await this : this >this : this } } diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.types b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.types index 90f89654c0518..da378ee2718f9 100644 --- a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.types +++ b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es5.types @@ -6,9 +6,9 @@ class C { >method : () => void var fn = async () => await this; ->fn : () => Promise> ->async () => await this : () => Promise> ->await this : Awaited +>fn : () => Promise +>async () => await this : () => Promise +>await this : this >this : this } } diff --git a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es6.types b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es6.types index 3b77fc642e4a2..5386a956ada9a 100644 --- a/tests/baselines/reference/asyncArrowFunctionCapturesThis_es6.types +++ b/tests/baselines/reference/asyncArrowFunctionCapturesThis_es6.types @@ -6,9 +6,9 @@ class C { >method : () => void var fn = async () => await this; ->fn : () => Promise> ->async () => await this : () => Promise> ->await this : Awaited +>fn : () => Promise +>async () => await this : () => Promise +>await this : this >this : this } } diff --git a/tests/baselines/reference/awaitedType.errors.txt b/tests/baselines/reference/awaitedType.errors.txt index 27441196136b1..731e3720f8ed5 100644 --- a/tests/baselines/reference/awaitedType.errors.txt +++ b/tests/baselines/reference/awaitedType.errors.txt @@ -47,6 +47,122 @@ tests/cases/compiler/awaitedType.ts(22,12): error TS2589: Type instantiation is ]) } + // non-generic + async function f1(x: string) { + // y: string + const y = await x; + } + + async function f2(x: unknown) { + // y: unknown + const y = await x; + } + + async function f3(x: object) { + // y: object + const y = await x; + } + + async function f4(x: Promise) { + // y: string + const y = await x; + } + + async function f5(x: Promise) { + // y: unknown + const y = await x; + } + + async function f6(x: Promise) { + // y: object + const y = await x; + } + + // generic + + async function f7(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; + } + + async function f8(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; + } + + async function f9(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; + } + + async function f10(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; + } + + async function f11 void): void }>(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; + } + + async function f12(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; + } + + async function f13(x: T) { + // NOTE: T belongs to the domain of primitive types + + // y: T + const y = await x; + } + + async function f14(x: T) { + // NOTE: T has a non-primitive base constraint without a callable `then`. + + // y: T + const y = await x; + } + + async function f15(x: T) { + // NOTE: T has a non-primitive base constraint without a callable `then`. + + // y: T + const y = await x; + } + + async function f16(x: T) { + // NOTE: T belongs to the domain of primitive types (regardless of `then`) + + // y: T + const y = await x; + } + + // helps with tests where '.types' just prints out the type alias name type _Expect = TActual; \ No newline at end of file diff --git a/tests/baselines/reference/awaitedType.js b/tests/baselines/reference/awaitedType.js index 57ad66fa51fb9..4c1485c9d0188 100644 --- a/tests/baselines/reference/awaitedType.js +++ b/tests/baselines/reference/awaitedType.js @@ -39,6 +39,122 @@ async function main() { ]) } +// non-generic +async function f1(x: string) { + // y: string + const y = await x; +} + +async function f2(x: unknown) { + // y: unknown + const y = await x; +} + +async function f3(x: object) { + // y: object + const y = await x; +} + +async function f4(x: Promise) { + // y: string + const y = await x; +} + +async function f5(x: Promise) { + // y: unknown + const y = await x; +} + +async function f6(x: Promise) { + // y: object + const y = await x; +} + +// generic + +async function f7(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +} + +async function f8(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +} + +async function f9(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +} + +async function f10(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +} + +async function f11 void): void }>(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +} + +async function f12(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +} + +async function f13(x: T) { + // NOTE: T belongs to the domain of primitive types + + // y: T + const y = await x; +} + +async function f14(x: T) { + // NOTE: T has a non-primitive base constraint without a callable `then`. + + // y: T + const y = await x; +} + +async function f15(x: T) { + // NOTE: T has a non-primitive base constraint without a callable `then`. + + // y: T + const y = await x; +} + +async function f16(x: T) { + // NOTE: T belongs to the domain of primitive types (regardless of `then`) + + // y: T + const y = await x; +} + + // helps with tests where '.types' just prints out the type alias name type _Expect = TActual; @@ -56,3 +172,91 @@ async function main() { MaybePromise(true), ]); } +// non-generic +async function f1(x) { + // y: string + const y = await x; +} +async function f2(x) { + // y: unknown + const y = await x; +} +async function f3(x) { + // y: object + const y = await x; +} +async function f4(x) { + // y: string + const y = await x; +} +async function f5(x) { + // y: unknown + const y = await x; +} +async function f6(x) { + // y: object + const y = await x; +} +// generic +async function f7(x) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + // y: Awaited + const y = await x; +} +async function f8(x) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + // y: Awaited + const y = await x; +} +async function f9(x) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + // y: Awaited + const y = await x; +} +async function f10(x) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + // y: Awaited + const y = await x; +} +async function f11(x) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + // y: Awaited + const y = await x; +} +async function f12(x) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + // y: Awaited + const y = await x; +} +async function f13(x) { + // NOTE: T belongs to the domain of primitive types + // y: T + const y = await x; +} +async function f14(x) { + // NOTE: T has a non-primitive base constraint without a callable `then`. + // y: T + const y = await x; +} +async function f15(x) { + // NOTE: T has a non-primitive base constraint without a callable `then`. + // y: T + const y = await x; +} +async function f16(x) { + // NOTE: T belongs to the domain of primitive types (regardless of `then`) + // y: T + const y = await x; +} diff --git a/tests/baselines/reference/awaitedType.symbols b/tests/baselines/reference/awaitedType.symbols index af4347bc1bc59..31e6093852ef0 100644 --- a/tests/baselines/reference/awaitedType.symbols +++ b/tests/baselines/reference/awaitedType.symbols @@ -60,21 +60,21 @@ type T12 = Awaited>>; type T13 = _Expect> | string | null>, /*expected*/ string | number | null>; // otherwise just prints T13 in types tests, which isn't very helpful >T13 : Symbol(T13, Decl(awaitedType.ts, 11, 45)) ->_Expect : Symbol(_Expect, Decl(awaitedType.ts, 38, 1)) +>_Expect : Symbol(_Expect, Decl(awaitedType.ts, 153, 1)) >Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) type T14 = _Expect> | string | undefined>, /*expected*/ string | number | undefined>; // otherwise just prints T14 in types tests, which isn't very helpful >T14 : Symbol(T14, Decl(awaitedType.ts, 12, 107)) ->_Expect : Symbol(_Expect, Decl(awaitedType.ts, 38, 1)) +>_Expect : Symbol(_Expect, Decl(awaitedType.ts, 153, 1)) >Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) type T15 = _Expect> | string | null | undefined>, /*expected*/ string | number | null | undefined>; // otherwise just prints T15 in types tests, which isn't very helpful >T15 : Symbol(T15, Decl(awaitedType.ts, 13, 117)) ->_Expect : Symbol(_Expect, Decl(awaitedType.ts, 38, 1)) +>_Expect : Symbol(_Expect, Decl(awaitedType.ts, 153, 1)) >Awaited : Symbol(Awaited, Decl(lib.es5.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, --, --), Decl(lib.es2018.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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) @@ -161,11 +161,236 @@ async function main() { ]) } +// non-generic +async function f1(x: string) { +>f1 : Symbol(f1, Decl(awaitedType.ts, 38, 1)) +>x : Symbol(x, Decl(awaitedType.ts, 41, 18)) + + // y: string + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 43, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 41, 18)) +} + +async function f2(x: unknown) { +>f2 : Symbol(f2, Decl(awaitedType.ts, 44, 1)) +>x : Symbol(x, Decl(awaitedType.ts, 46, 18)) + + // y: unknown + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 48, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 46, 18)) +} + +async function f3(x: object) { +>f3 : Symbol(f3, Decl(awaitedType.ts, 49, 1)) +>x : Symbol(x, Decl(awaitedType.ts, 51, 18)) + + // y: object + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 53, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 51, 18)) +} + +async function f4(x: Promise) { +>f4 : Symbol(f4, Decl(awaitedType.ts, 54, 1)) +>x : Symbol(x, Decl(awaitedType.ts, 56, 18)) +>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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + + // y: string + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 58, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 56, 18)) +} + +async function f5(x: Promise) { +>f5 : Symbol(f5, Decl(awaitedType.ts, 59, 1)) +>x : Symbol(x, Decl(awaitedType.ts, 61, 18)) +>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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + + // y: unknown + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 63, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 61, 18)) +} + +async function f6(x: Promise) { +>f6 : Symbol(f6, Decl(awaitedType.ts, 64, 1)) +>x : Symbol(x, Decl(awaitedType.ts, 66, 18)) +>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, --, --), Decl(lib.es2018.promise.d.ts, --, --)) + + // y: object + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 68, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 66, 18)) +} + +// generic + +async function f7(x: T) { +>f7 : Symbol(f7, Decl(awaitedType.ts, 69, 1)) +>T : Symbol(T, Decl(awaitedType.ts, 73, 18)) +>x : Symbol(x, Decl(awaitedType.ts, 73, 21)) +>T : Symbol(T, Decl(awaitedType.ts, 73, 18)) + + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 79, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 73, 21)) +} + +async function f8(x: T) { +>f8 : Symbol(f8, Decl(awaitedType.ts, 80, 1)) +>T : Symbol(T, Decl(awaitedType.ts, 82, 18)) +>x : Symbol(x, Decl(awaitedType.ts, 82, 33)) +>T : Symbol(T, Decl(awaitedType.ts, 82, 18)) + + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 88, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 82, 33)) +} + +async function f9(x: T) { +>f9 : Symbol(f9, Decl(awaitedType.ts, 89, 1)) +>T : Symbol(T, Decl(awaitedType.ts, 91, 18)) +>x : Symbol(x, Decl(awaitedType.ts, 91, 37)) +>T : Symbol(T, Decl(awaitedType.ts, 91, 18)) + + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 97, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 91, 37)) +} + +async function f10(x: T) { +>f10 : Symbol(f10, Decl(awaitedType.ts, 98, 1)) +>T : Symbol(T, Decl(awaitedType.ts, 100, 19)) +>x : Symbol(x, Decl(awaitedType.ts, 100, 33)) +>T : Symbol(T, Decl(awaitedType.ts, 100, 19)) + + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 106, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 100, 33)) +} + +async function f11 void): void }>(x: T) { +>f11 : Symbol(f11, Decl(awaitedType.ts, 107, 1)) +>T : Symbol(T, Decl(awaitedType.ts, 109, 19)) +>then : Symbol(then, Decl(awaitedType.ts, 109, 30)) +>onfulfilled : Symbol(onfulfilled, Decl(awaitedType.ts, 109, 36)) +>value : Symbol(value, Decl(awaitedType.ts, 109, 50)) +>x : Symbol(x, Decl(awaitedType.ts, 109, 84)) +>T : Symbol(T, Decl(awaitedType.ts, 109, 19)) + + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 115, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 109, 84)) +} + +async function f12(x: T) { +>f12 : Symbol(f12, Decl(awaitedType.ts, 116, 1)) +>T : Symbol(T, Decl(awaitedType.ts, 118, 19)) +>x : Symbol(x, Decl(awaitedType.ts, 118, 46)) +>T : Symbol(T, Decl(awaitedType.ts, 118, 19)) + + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 124, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 118, 46)) +} + +async function f13(x: T) { +>f13 : Symbol(f13, Decl(awaitedType.ts, 125, 1)) +>T : Symbol(T, Decl(awaitedType.ts, 127, 19)) +>x : Symbol(x, Decl(awaitedType.ts, 127, 37)) +>T : Symbol(T, Decl(awaitedType.ts, 127, 19)) + + // NOTE: T belongs to the domain of primitive types + + // y: T + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 131, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 127, 37)) +} + +async function f14(x: T) { +>f14 : Symbol(f14, Decl(awaitedType.ts, 132, 1)) +>T : Symbol(T, Decl(awaitedType.ts, 134, 19)) +>x : Symbol(x, Decl(awaitedType.ts, 134, 30)) +>x : Symbol(x, Decl(awaitedType.ts, 134, 44)) +>T : Symbol(T, Decl(awaitedType.ts, 134, 19)) + + // NOTE: T has a non-primitive base constraint without a callable `then`. + + // y: T + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 138, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 134, 44)) +} + +async function f15(x: T) { +>f15 : Symbol(f15, Decl(awaitedType.ts, 139, 1)) +>T : Symbol(T, Decl(awaitedType.ts, 141, 19)) +>then : Symbol(then, Decl(awaitedType.ts, 141, 30)) +>x : Symbol(x, Decl(awaitedType.ts, 141, 47)) +>T : Symbol(T, Decl(awaitedType.ts, 141, 19)) + + // NOTE: T has a non-primitive base constraint without a callable `then`. + + // y: T + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 145, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 141, 47)) +} + +async function f16(x: T) { +>f16 : Symbol(f16, Decl(awaitedType.ts, 146, 1)) +>T : Symbol(T, Decl(awaitedType.ts, 148, 19)) +>then : Symbol(then, Decl(awaitedType.ts, 148, 39)) +>x : Symbol(x, Decl(awaitedType.ts, 148, 56)) +>T : Symbol(T, Decl(awaitedType.ts, 148, 19)) + + // NOTE: T belongs to the domain of primitive types (regardless of `then`) + + // y: T + const y = await x; +>y : Symbol(y, Decl(awaitedType.ts, 152, 9)) +>x : Symbol(x, Decl(awaitedType.ts, 148, 56)) +} + + // helps with tests where '.types' just prints out the type alias name type _Expect = TActual; ->_Expect : Symbol(_Expect, Decl(awaitedType.ts, 38, 1)) ->TActual : Symbol(TActual, Decl(awaitedType.ts, 41, 13)) ->TExpected : Symbol(TExpected, Decl(awaitedType.ts, 41, 39)) ->TExpected : Symbol(TExpected, Decl(awaitedType.ts, 41, 39)) ->TActual : Symbol(TActual, Decl(awaitedType.ts, 41, 13)) +>_Expect : Symbol(_Expect, Decl(awaitedType.ts, 153, 1)) +>TActual : Symbol(TActual, Decl(awaitedType.ts, 157, 13)) +>TExpected : Symbol(TExpected, Decl(awaitedType.ts, 157, 39)) +>TExpected : Symbol(TExpected, Decl(awaitedType.ts, 157, 39)) +>TActual : Symbol(TActual, Decl(awaitedType.ts, 157, 13)) diff --git a/tests/baselines/reference/awaitedType.types b/tests/baselines/reference/awaitedType.types index 0da35c5532eab..86d8402812dba 100644 --- a/tests/baselines/reference/awaitedType.types +++ b/tests/baselines/reference/awaitedType.types @@ -128,6 +128,224 @@ async function main() { ]) } +// non-generic +async function f1(x: string) { +>f1 : (x: string) => Promise +>x : string + + // y: string + const y = await x; +>y : string +>await x : string +>x : string +} + +async function f2(x: unknown) { +>f2 : (x: unknown) => Promise +>x : unknown + + // y: unknown + const y = await x; +>y : unknown +>await x : unknown +>x : unknown +} + +async function f3(x: object) { +>f3 : (x: object) => Promise +>x : object + + // y: object + const y = await x; +>y : object +>await x : object +>x : object +} + +async function f4(x: Promise) { +>f4 : (x: Promise) => Promise +>x : Promise + + // y: string + const y = await x; +>y : string +>await x : string +>x : Promise +} + +async function f5(x: Promise) { +>f5 : (x: Promise) => Promise +>x : Promise + + // y: unknown + const y = await x; +>y : unknown +>await x : unknown +>x : Promise +} + +async function f6(x: Promise) { +>f6 : (x: Promise) => Promise +>x : Promise + + // y: object + const y = await x; +>y : object +>await x : object +>x : Promise +} + +// generic + +async function f7(x: T) { +>f7 : (x: T) => Promise +>x : T + + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +>y : Awaited +>await x : Awaited +>x : T +} + +async function f8(x: T) { +>f8 : (x: T) => Promise +>x : T + + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +>y : Awaited +>await x : Awaited +>x : T +} + +async function f9(x: T) { +>f9 : (x: T) => Promise +>x : T + + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +>y : Awaited +>await x : Awaited +>x : T +} + +async function f10(x: T) { +>f10 : (x: T) => Promise +>x : T + + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +>y : Awaited +>await x : Awaited +>x : T +} + +async function f11 void): void }>(x: T) { +>f11 : void): void; }>(x: T) => Promise +>then : (onfulfilled: (value: unknown) => void) => void +>onfulfilled : (value: unknown) => void +>value : unknown +>x : T + + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +>y : unknown +>await x : unknown +>x : T +} + +async function f12(x: T) { +>f12 : (x: T) => Promise +>x : T + + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +>y : Awaited +>await x : Awaited +>x : T +} + +async function f13(x: T) { +>f13 : (x: T) => Promise +>x : T + + // NOTE: T belongs to the domain of primitive types + + // y: T + const y = await x; +>y : T +>await x : T +>x : T +} + +async function f14(x: T) { +>f14 : (x: T) => Promise +>x : number +>x : T + + // NOTE: T has a non-primitive base constraint without a callable `then`. + + // y: T + const y = await x; +>y : T +>await x : T +>x : T +} + +async function f15(x: T) { +>f15 : (x: T) => Promise +>then : number +>x : T + + // NOTE: T has a non-primitive base constraint without a callable `then`. + + // y: T + const y = await x; +>y : T +>await x : T +>x : T +} + +async function f16(x: T) { +>f16 : (x: T) => Promise +>then : () => void +>x : T + + // NOTE: T belongs to the domain of primitive types (regardless of `then`) + + // y: T + const y = await x; +>y : T +>await x : T +>x : T +} + + // helps with tests where '.types' just prints out the type alias name type _Expect = TActual; >_Expect : TActual diff --git a/tests/cases/compiler/awaitedType.ts b/tests/cases/compiler/awaitedType.ts index 2a92edd930a2f..13c046685f1b4 100644 --- a/tests/cases/compiler/awaitedType.ts +++ b/tests/cases/compiler/awaitedType.ts @@ -41,5 +41,121 @@ async function main() { ]) } +// non-generic +async function f1(x: string) { + // y: string + const y = await x; +} + +async function f2(x: unknown) { + // y: unknown + const y = await x; +} + +async function f3(x: object) { + // y: object + const y = await x; +} + +async function f4(x: Promise) { + // y: string + const y = await x; +} + +async function f5(x: Promise) { + // y: unknown + const y = await x; +} + +async function f6(x: Promise) { + // y: object + const y = await x; +} + +// generic + +async function f7(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +} + +async function f8(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +} + +async function f9(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +} + +async function f10(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +} + +async function f11 void): void }>(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +} + +async function f12(x: T) { + // NOTE: T does not belong solely to the domain of primitive types and either does + // not have a base constraint, its base constraint is `any`, `unknown`, `{}`, or `object`, + // or it has a non-primitive base constraint with a callable `then`. + + // y: Awaited + const y = await x; +} + +async function f13(x: T) { + // NOTE: T belongs to the domain of primitive types + + // y: T + const y = await x; +} + +async function f14(x: T) { + // NOTE: T has a non-primitive base constraint without a callable `then`. + + // y: T + const y = await x; +} + +async function f15(x: T) { + // NOTE: T has a non-primitive base constraint without a callable `then`. + + // y: T + const y = await x; +} + +async function f16(x: T) { + // NOTE: T belongs to the domain of primitive types (regardless of `then`) + + // y: T + const y = await x; +} + + // helps with tests where '.types' just prints out the type alias name type _Expect = TActual;