From f0ef4a967b7f90d9190cdffc25401e2b2697fa2e Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Sun, 4 Feb 2018 18:44:43 -0800 Subject: [PATCH] Minor cleanup and some related tests --- src/lib/es5.d.ts | 12 +- tests/baselines/reference/awaitedOfT.js | 44 ++++ tests/baselines/reference/awaitedOfT.symbols | 236 +++++++++++++++++++ tests/baselines/reference/awaitedOfT.types | 236 +++++++++++++++++++ tests/cases/compiler/awaitedOfT.ts | 42 ++++ 5 files changed, 562 insertions(+), 8 deletions(-) create mode 100644 tests/baselines/reference/awaitedOfT.js create mode 100644 tests/baselines/reference/awaitedOfT.symbols create mode 100644 tests/baselines/reference/awaitedOfT.types create mode 100644 tests/cases/compiler/awaitedOfT.ts diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 21ae358369713..44fd9bfcba666 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1273,17 +1273,13 @@ declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) declare type MethodDecorator = (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void; declare type ParameterDecorator = (target: Object, propertyKey: string | symbol, parameterIndex: number) => void; -/** An object type that can be definitely be awaited. Do not inherit from this type. */ +/** An object type that can definitely be awaited. Do not inherit from this type. */ declare type Awaitable = { then(onfulfilled: (value: T) => any): any; }; -/** An object type that may not be awaitable. Do not inherit from this type. */ -declare type NonAwaitable = { then(...args: any[]): any; }; - -/** Gets the type resulting from awaiting `T`. This does **not** recursively unwrap nested promises. */ +/** Gets the resulting type from awaiting `T`. This does **not** recursively unwrap nested promises. */ declare type Awaited = - T extends Awaitable> ? U : - T extends Awaitable ? U : - T extends NonAwaitable ? never : + T extends Awaitable ? U extends T ? never : U : + T extends { then(...args: any[]): any; } ? never : T; declare type PromiseConstructorLike = new (executor: (resolve: (value?: T | Awaitable) => void, reject: (reason?: any) => void) => void) => PromiseLike; diff --git a/tests/baselines/reference/awaitedOfT.js b/tests/baselines/reference/awaitedOfT.js new file mode 100644 index 0000000000000..190d509af0b67 --- /dev/null +++ b/tests/baselines/reference/awaitedOfT.js @@ -0,0 +1,44 @@ +//// [awaitedOfT.ts] +type T1 = Awaited; // number (same as 'await') +type T2 = Awaited>; // number (same as 'await') +type T3 = Awaited>>; // number (same as 'await') +type T4 = Awaited>>>; // number (same as 'await') +type T5 = Awaited>; // number (same as 'await') +type T6 = Awaited>>; // number (same as 'await') +type T7 = Awaited>>>; // number (same as 'await') +type T8 = Awaited>>; // number (same as 'await') +type T9 = Awaited>>; // number (same as 'await') +type T10 = Awaited<{ then: any; }>; // never (no way to know what this might resolve to, differs from 'await') +type T11 = Awaited<{ then: number; }>; // { then: number; } (same as 'await') +type T12 = Awaited<{ then(): void; }>; // never (no way to know what this might resolve to, error for 'await') +type T13 = Awaited<{ then(x: any): void; }>; // never (no way to know what this might resolve to, error for 'await') +type T14 = Awaited<{ then(x: number): void; }>; // never (cannot be resolved correctly, error for 'await') +type T15 = Awaited<{ then(x: () => void): void; }>; // never (no way to know what this might resolve to) +type T16 = Awaited<{ then(x: (y: any) => void): void; }>; // any (same as 'await') +type T17 = Awaited<{ then(x: (y: number) => void): void; }>; // number (same as 'await') +type T18 = Awaited<{ then(x: (y: { then: any; }) => void): void; }>; // { then: any; } (no recursive unwrap, differs from 'await') +type T19 = Awaited<{ then(x: (y: { then: number; }) => void): void; }>; // { then: number; } (no recursive unwrap, differs from 'await') +type T20 = Awaited<{ then(x: (y: { then(): void; }) => void): void; }>; // { then(): void; } (no recursive unwrap, differs from 'await') +type T21 = Awaited<{ then(x: (y: { then(x: any): void; }) => void): void; }>; // { then(x: any): void; } (no recursive unwrap, differs from 'await') +type T22 = Awaited<{ then(x: (y: { then(x: number): void; }) => void): void; }>; // { then(x: number): void; } (no recursive unwrap, differs from 'await') +type T23 = Awaited<{ then(x: (y: { then(x: () => void): void; }) => void): void; }>; // { then(x: () => void): void; } (no recursive unwrap, differs from 'await') +type T24 = Awaited<{ then(x: (y: { then(x: (y: any) => void): void; }) => void): void; }>; // { then(x: (y: any) => void): void; } (no recursive unwrap, differs from 'await') +type T25 = Awaited<{ then(x: (y: { then(x: (y: number) => void): void; }) => void): void; }>; // { then(x: (y: number) => void): void; } (no recursive unwrap, differs from 'await') + +// self recursive bad promise +type T26 = Awaited; // BadPromise (no recursive unwrap, differs from 'await') +interface BadPromise { then(cb: (value: BadPromise) => void): any; } + +// mutually recursive bad promises +type T27 = Awaited; // BadPromiseB (no recursive unwrap, differs from 'await') +interface BadPromiseA { then(cb: (value: BadPromiseB) => void): any; } +interface BadPromiseB { then(cb: (value: BadPromiseA) => void): any; } + +type T28 = Awaited; // never (same as 'await') +type T29 = Awaited>; // string | number (same as 'await') +type T30 = Awaited>; // number (same as 'await') +type T31 = Awaited | Promise>; // string | number (same as 'await') +type T32 = Awaited>; // number (same as 'await') +type T33 = Awaited>>>; // number (same as 'await') + +//// [awaitedOfT.js] diff --git a/tests/baselines/reference/awaitedOfT.symbols b/tests/baselines/reference/awaitedOfT.symbols new file mode 100644 index 0000000000000..e1191e2ce24b8 --- /dev/null +++ b/tests/baselines/reference/awaitedOfT.symbols @@ -0,0 +1,236 @@ +=== tests/cases/compiler/awaitedOfT.ts === +type T1 = Awaited; // number (same as 'await') +>T1 : Symbol(T1, Decl(awaitedOfT.ts, 0, 0)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T2 = Awaited>; // number (same as 'await') +>T2 : Symbol(T2, Decl(awaitedOfT.ts, 0, 26)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + +type T3 = Awaited>>; // number (same as 'await') +>T3 : Symbol(T3, Decl(awaitedOfT.ts, 1, 35)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + +type T4 = Awaited>>>; // number (same as 'await') +>T4 : Symbol(T4, Decl(awaitedOfT.ts, 2, 44)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + +type T5 = Awaited>; // number (same as 'await') +>T5 : Symbol(T5, Decl(awaitedOfT.ts, 3, 53)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --)) + +type T6 = Awaited>>; // number (same as 'await') +>T6 : Symbol(T6, Decl(awaitedOfT.ts, 4, 39)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --)) +>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --)) + +type T7 = Awaited>>>; // number (same as 'await') +>T7 : Symbol(T7, Decl(awaitedOfT.ts, 5, 52)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --)) +>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --)) +>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --)) + +type T8 = Awaited>>; // number (same as 'await') +>T8 : Symbol(T8, Decl(awaitedOfT.ts, 6, 65)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --)) + +type T9 = Awaited>>; // number (same as 'await') +>T9 : Symbol(T9, Decl(awaitedOfT.ts, 7, 48)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + +type T10 = Awaited<{ then: any; }>; // never (no way to know what this might resolve to, differs from 'await') +>T10 : Symbol(T10, Decl(awaitedOfT.ts, 8, 48)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedOfT.ts, 9, 20)) + +type T11 = Awaited<{ then: number; }>; // { then: number; } (same as 'await') +>T11 : Symbol(T11, Decl(awaitedOfT.ts, 9, 35)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedOfT.ts, 10, 20)) + +type T12 = Awaited<{ then(): void; }>; // never (no way to know what this might resolve to, error for 'await') +>T12 : Symbol(T12, Decl(awaitedOfT.ts, 10, 38)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedOfT.ts, 11, 20)) + +type T13 = Awaited<{ then(x: any): void; }>; // never (no way to know what this might resolve to, error for 'await') +>T13 : Symbol(T13, Decl(awaitedOfT.ts, 11, 38)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedOfT.ts, 12, 20)) +>x : Symbol(x, Decl(awaitedOfT.ts, 12, 26)) + +type T14 = Awaited<{ then(x: number): void; }>; // never (cannot be resolved correctly, error for 'await') +>T14 : Symbol(T14, Decl(awaitedOfT.ts, 12, 44)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedOfT.ts, 13, 20)) +>x : Symbol(x, Decl(awaitedOfT.ts, 13, 26)) + +type T15 = Awaited<{ then(x: () => void): void; }>; // never (no way to know what this might resolve to) +>T15 : Symbol(T15, Decl(awaitedOfT.ts, 13, 47)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedOfT.ts, 14, 20)) +>x : Symbol(x, Decl(awaitedOfT.ts, 14, 26)) + +type T16 = Awaited<{ then(x: (y: any) => void): void; }>; // any (same as 'await') +>T16 : Symbol(T16, Decl(awaitedOfT.ts, 14, 51)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedOfT.ts, 15, 20)) +>x : Symbol(x, Decl(awaitedOfT.ts, 15, 26)) +>y : Symbol(y, Decl(awaitedOfT.ts, 15, 30)) + +type T17 = Awaited<{ then(x: (y: number) => void): void; }>; // number (same as 'await') +>T17 : Symbol(T17, Decl(awaitedOfT.ts, 15, 57)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedOfT.ts, 16, 20)) +>x : Symbol(x, Decl(awaitedOfT.ts, 16, 26)) +>y : Symbol(y, Decl(awaitedOfT.ts, 16, 30)) + +type T18 = Awaited<{ then(x: (y: { then: any; }) => void): void; }>; // { then: any; } (no recursive unwrap, differs from 'await') +>T18 : Symbol(T18, Decl(awaitedOfT.ts, 16, 60)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedOfT.ts, 17, 20)) +>x : Symbol(x, Decl(awaitedOfT.ts, 17, 26)) +>y : Symbol(y, Decl(awaitedOfT.ts, 17, 30)) +>then : Symbol(then, Decl(awaitedOfT.ts, 17, 34)) + +type T19 = Awaited<{ then(x: (y: { then: number; }) => void): void; }>; // { then: number; } (no recursive unwrap, differs from 'await') +>T19 : Symbol(T19, Decl(awaitedOfT.ts, 17, 68)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedOfT.ts, 18, 20)) +>x : Symbol(x, Decl(awaitedOfT.ts, 18, 26)) +>y : Symbol(y, Decl(awaitedOfT.ts, 18, 30)) +>then : Symbol(then, Decl(awaitedOfT.ts, 18, 34)) + +type T20 = Awaited<{ then(x: (y: { then(): void; }) => void): void; }>; // { then(): void; } (no recursive unwrap, differs from 'await') +>T20 : Symbol(T20, Decl(awaitedOfT.ts, 18, 71)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedOfT.ts, 19, 20)) +>x : Symbol(x, Decl(awaitedOfT.ts, 19, 26)) +>y : Symbol(y, Decl(awaitedOfT.ts, 19, 30)) +>then : Symbol(then, Decl(awaitedOfT.ts, 19, 34)) + +type T21 = Awaited<{ then(x: (y: { then(x: any): void; }) => void): void; }>; // { then(x: any): void; } (no recursive unwrap, differs from 'await') +>T21 : Symbol(T21, Decl(awaitedOfT.ts, 19, 71)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedOfT.ts, 20, 20)) +>x : Symbol(x, Decl(awaitedOfT.ts, 20, 26)) +>y : Symbol(y, Decl(awaitedOfT.ts, 20, 30)) +>then : Symbol(then, Decl(awaitedOfT.ts, 20, 34)) +>x : Symbol(x, Decl(awaitedOfT.ts, 20, 40)) + +type T22 = Awaited<{ then(x: (y: { then(x: number): void; }) => void): void; }>; // { then(x: number): void; } (no recursive unwrap, differs from 'await') +>T22 : Symbol(T22, Decl(awaitedOfT.ts, 20, 77)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedOfT.ts, 21, 20)) +>x : Symbol(x, Decl(awaitedOfT.ts, 21, 26)) +>y : Symbol(y, Decl(awaitedOfT.ts, 21, 30)) +>then : Symbol(then, Decl(awaitedOfT.ts, 21, 34)) +>x : Symbol(x, Decl(awaitedOfT.ts, 21, 40)) + +type T23 = Awaited<{ then(x: (y: { then(x: () => void): void; }) => void): void; }>; // { then(x: () => void): void; } (no recursive unwrap, differs from 'await') +>T23 : Symbol(T23, Decl(awaitedOfT.ts, 21, 80)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedOfT.ts, 22, 20)) +>x : Symbol(x, Decl(awaitedOfT.ts, 22, 26)) +>y : Symbol(y, Decl(awaitedOfT.ts, 22, 30)) +>then : Symbol(then, Decl(awaitedOfT.ts, 22, 34)) +>x : Symbol(x, Decl(awaitedOfT.ts, 22, 40)) + +type T24 = Awaited<{ then(x: (y: { then(x: (y: any) => void): void; }) => void): void; }>; // { then(x: (y: any) => void): void; } (no recursive unwrap, differs from 'await') +>T24 : Symbol(T24, Decl(awaitedOfT.ts, 22, 84)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedOfT.ts, 23, 20)) +>x : Symbol(x, Decl(awaitedOfT.ts, 23, 26)) +>y : Symbol(y, Decl(awaitedOfT.ts, 23, 30)) +>then : Symbol(then, Decl(awaitedOfT.ts, 23, 34)) +>x : Symbol(x, Decl(awaitedOfT.ts, 23, 40)) +>y : Symbol(y, Decl(awaitedOfT.ts, 23, 44)) + +type T25 = Awaited<{ then(x: (y: { then(x: (y: number) => void): void; }) => void): void; }>; // { then(x: (y: number) => void): void; } (no recursive unwrap, differs from 'await') +>T25 : Symbol(T25, Decl(awaitedOfT.ts, 23, 90)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>then : Symbol(then, Decl(awaitedOfT.ts, 24, 20)) +>x : Symbol(x, Decl(awaitedOfT.ts, 24, 26)) +>y : Symbol(y, Decl(awaitedOfT.ts, 24, 30)) +>then : Symbol(then, Decl(awaitedOfT.ts, 24, 34)) +>x : Symbol(x, Decl(awaitedOfT.ts, 24, 40)) +>y : Symbol(y, Decl(awaitedOfT.ts, 24, 44)) + +// self recursive bad promise +type T26 = Awaited; // BadPromise (no recursive unwrap, differs from 'await') +>T26 : Symbol(T26, Decl(awaitedOfT.ts, 24, 93)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>BadPromise : Symbol(BadPromise, Decl(awaitedOfT.ts, 27, 31)) + +interface BadPromise { then(cb: (value: BadPromise) => void): any; } +>BadPromise : Symbol(BadPromise, Decl(awaitedOfT.ts, 27, 31)) +>then : Symbol(BadPromise.then, Decl(awaitedOfT.ts, 28, 22)) +>cb : Symbol(cb, Decl(awaitedOfT.ts, 28, 28)) +>value : Symbol(value, Decl(awaitedOfT.ts, 28, 33)) +>BadPromise : Symbol(BadPromise, Decl(awaitedOfT.ts, 27, 31)) + +// mutually recursive bad promises +type T27 = Awaited; // BadPromiseB (no recursive unwrap, differs from 'await') +>T27 : Symbol(T27, Decl(awaitedOfT.ts, 28, 68)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>BadPromiseA : Symbol(BadPromiseA, Decl(awaitedOfT.ts, 31, 32)) + +interface BadPromiseA { then(cb: (value: BadPromiseB) => void): any; } +>BadPromiseA : Symbol(BadPromiseA, Decl(awaitedOfT.ts, 31, 32)) +>then : Symbol(BadPromiseA.then, Decl(awaitedOfT.ts, 32, 23)) +>cb : Symbol(cb, Decl(awaitedOfT.ts, 32, 29)) +>value : Symbol(value, Decl(awaitedOfT.ts, 32, 34)) +>BadPromiseB : Symbol(BadPromiseB, Decl(awaitedOfT.ts, 32, 70)) + +interface BadPromiseB { then(cb: (value: BadPromiseA) => void): any; } +>BadPromiseB : Symbol(BadPromiseB, Decl(awaitedOfT.ts, 32, 70)) +>then : Symbol(BadPromiseB.then, Decl(awaitedOfT.ts, 33, 23)) +>cb : Symbol(cb, Decl(awaitedOfT.ts, 33, 29)) +>value : Symbol(value, Decl(awaitedOfT.ts, 33, 34)) +>BadPromiseA : Symbol(BadPromiseA, Decl(awaitedOfT.ts, 31, 32)) + +type T28 = Awaited; // never (same as 'await') +>T28 : Symbol(T28, Decl(awaitedOfT.ts, 33, 70)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T29 = Awaited>; // string | number (same as 'await') +>T29 : Symbol(T29, Decl(awaitedOfT.ts, 35, 26)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + +type T30 = Awaited>; // number (same as 'await') +>T30 : Symbol(T30, Decl(awaitedOfT.ts, 36, 45)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + +type T31 = Awaited | Promise>; // string | number (same as 'await') +>T31 : Symbol(T31, Decl(awaitedOfT.ts, 37, 44)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + +type T32 = Awaited>; // number (same as 'await') +>T32 : Symbol(T32, Decl(awaitedOfT.ts, 38, 58)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + +type T33 = Awaited>>>; // number (same as 'await') +>T33 : Symbol(T33, Decl(awaitedOfT.ts, 39, 36)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) + diff --git a/tests/baselines/reference/awaitedOfT.types b/tests/baselines/reference/awaitedOfT.types new file mode 100644 index 0000000000000..e112a69ca46c0 --- /dev/null +++ b/tests/baselines/reference/awaitedOfT.types @@ -0,0 +1,236 @@ +=== tests/cases/compiler/awaitedOfT.ts === +type T1 = Awaited; // number (same as 'await') +>T1 : number +>Awaited : Awaited + +type T2 = Awaited>; // number (same as 'await') +>T2 : number +>Awaited : Awaited +>Promise : Promise + +type T3 = Awaited>>; // number (same as 'await') +>T3 : number +>Awaited : Awaited +>Promise : Promise +>Promise : Promise + +type T4 = Awaited>>>; // number (same as 'await') +>T4 : number +>Awaited : Awaited +>Promise : Promise +>Promise : Promise +>Promise : Promise + +type T5 = Awaited>; // number (same as 'await') +>T5 : number +>Awaited : Awaited +>PromiseLike : PromiseLike + +type T6 = Awaited>>; // number (same as 'await') +>T6 : number +>Awaited : Awaited +>PromiseLike : PromiseLike +>PromiseLike : PromiseLike + +type T7 = Awaited>>>; // number (same as 'await') +>T7 : number +>Awaited : Awaited +>PromiseLike : PromiseLike +>PromiseLike : PromiseLike +>PromiseLike : PromiseLike + +type T8 = Awaited>>; // number (same as 'await') +>T8 : number +>Awaited : Awaited +>Promise : Promise +>PromiseLike : PromiseLike + +type T9 = Awaited>>; // number (same as 'await') +>T9 : number +>Awaited : Awaited +>PromiseLike : PromiseLike +>Promise : Promise + +type T10 = Awaited<{ then: any; }>; // never (no way to know what this might resolve to, differs from 'await') +>T10 : never +>Awaited : Awaited +>then : any + +type T11 = Awaited<{ then: number; }>; // { then: number; } (same as 'await') +>T11 : { then: number; } +>Awaited : Awaited +>then : number + +type T12 = Awaited<{ then(): void; }>; // never (no way to know what this might resolve to, error for 'await') +>T12 : never +>Awaited : Awaited +>then : () => void + +type T13 = Awaited<{ then(x: any): void; }>; // never (no way to know what this might resolve to, error for 'await') +>T13 : never +>Awaited : Awaited +>then : (x: any) => void +>x : any + +type T14 = Awaited<{ then(x: number): void; }>; // never (cannot be resolved correctly, error for 'await') +>T14 : never +>Awaited : Awaited +>then : (x: number) => void +>x : number + +type T15 = Awaited<{ then(x: () => void): void; }>; // never (no way to know what this might resolve to) +>T15 : never +>Awaited : Awaited +>then : (x: () => void) => void +>x : () => void + +type T16 = Awaited<{ then(x: (y: any) => void): void; }>; // any (same as 'await') +>T16 : any +>Awaited : Awaited +>then : (x: (y: any) => void) => void +>x : (y: any) => void +>y : any + +type T17 = Awaited<{ then(x: (y: number) => void): void; }>; // number (same as 'await') +>T17 : number +>Awaited : Awaited +>then : (x: (y: number) => void) => void +>x : (y: number) => void +>y : number + +type T18 = Awaited<{ then(x: (y: { then: any; }) => void): void; }>; // { then: any; } (no recursive unwrap, differs from 'await') +>T18 : never +>Awaited : Awaited +>then : (x: (y: { then: any; }) => void) => void +>x : (y: { then: any; }) => void +>y : { then: any; } +>then : any + +type T19 = Awaited<{ then(x: (y: { then: number; }) => void): void; }>; // { then: number; } (no recursive unwrap, differs from 'await') +>T19 : { then: number; } +>Awaited : Awaited +>then : (x: (y: { then: number; }) => void) => void +>x : (y: { then: number; }) => void +>y : { then: number; } +>then : number + +type T20 = Awaited<{ then(x: (y: { then(): void; }) => void): void; }>; // { then(): void; } (no recursive unwrap, differs from 'await') +>T20 : never +>Awaited : Awaited +>then : (x: (y: { then(): void; }) => void) => void +>x : (y: { then(): void; }) => void +>y : { then(): void; } +>then : () => void + +type T21 = Awaited<{ then(x: (y: { then(x: any): void; }) => void): void; }>; // { then(x: any): void; } (no recursive unwrap, differs from 'await') +>T21 : never +>Awaited : Awaited +>then : (x: (y: { then(x: any): void; }) => void) => void +>x : (y: { then(x: any): void; }) => void +>y : { then(x: any): void; } +>then : (x: any) => void +>x : any + +type T22 = Awaited<{ then(x: (y: { then(x: number): void; }) => void): void; }>; // { then(x: number): void; } (no recursive unwrap, differs from 'await') +>T22 : { then(x: number): void; } +>Awaited : Awaited +>then : (x: (y: { then(x: number): void; }) => void) => void +>x : (y: { then(x: number): void; }) => void +>y : { then(x: number): void; } +>then : (x: number) => void +>x : number + +type T23 = Awaited<{ then(x: (y: { then(x: () => void): void; }) => void): void; }>; // { then(x: () => void): void; } (no recursive unwrap, differs from 'await') +>T23 : { then(x: () => void): void; } +>Awaited : Awaited +>then : (x: (y: { then(x: () => void): void; }) => void) => void +>x : (y: { then(x: () => void): void; }) => void +>y : { then(x: () => void): void; } +>then : (x: () => void) => void +>x : () => void + +type T24 = Awaited<{ then(x: (y: { then(x: (y: any) => void): void; }) => void): void; }>; // { then(x: (y: any) => void): void; } (no recursive unwrap, differs from 'await') +>T24 : never +>Awaited : Awaited +>then : (x: (y: { then(x: (y: any) => void): void; }) => void) => void +>x : (y: { then(x: (y: any) => void): void; }) => void +>y : { then(x: (y: any) => void): void; } +>then : (x: (y: any) => void) => void +>x : (y: any) => void +>y : any + +type T25 = Awaited<{ then(x: (y: { then(x: (y: number) => void): void; }) => void): void; }>; // { then(x: (y: number) => void): void; } (no recursive unwrap, differs from 'await') +>T25 : { then(x: (y: number) => void): void; } +>Awaited : Awaited +>then : (x: (y: { then(x: (y: number) => void): void; }) => void) => void +>x : (y: { then(x: (y: number) => void): void; }) => void +>y : { then(x: (y: number) => void): void; } +>then : (x: (y: number) => void) => void +>x : (y: number) => void +>y : number + +// self recursive bad promise +type T26 = Awaited; // BadPromise (no recursive unwrap, differs from 'await') +>T26 : never +>Awaited : Awaited +>BadPromise : BadPromise + +interface BadPromise { then(cb: (value: BadPromise) => void): any; } +>BadPromise : BadPromise +>then : (cb: (value: BadPromise) => void) => any +>cb : (value: BadPromise) => void +>value : BadPromise +>BadPromise : BadPromise + +// mutually recursive bad promises +type T27 = Awaited; // BadPromiseB (no recursive unwrap, differs from 'await') +>T27 : never +>Awaited : Awaited +>BadPromiseA : BadPromiseA + +interface BadPromiseA { then(cb: (value: BadPromiseB) => void): any; } +>BadPromiseA : BadPromiseA +>then : (cb: (value: BadPromiseB) => void) => any +>cb : (value: BadPromiseB) => void +>value : BadPromiseB +>BadPromiseB : BadPromiseB + +interface BadPromiseB { then(cb: (value: BadPromiseA) => void): any; } +>BadPromiseB : BadPromiseB +>then : (cb: (value: BadPromiseA) => void) => any +>cb : (value: BadPromiseA) => void +>value : BadPromiseA +>BadPromiseA : BadPromiseA + +type T28 = Awaited; // never (same as 'await') +>T28 : never +>Awaited : Awaited + +type T29 = Awaited>; // string | number (same as 'await') +>T29 : string | number +>Awaited : Awaited +>Promise : Promise + +type T30 = Awaited>; // number (same as 'await') +>T30 : number +>Awaited : Awaited +>Promise : Promise + +type T31 = Awaited | Promise>; // string | number (same as 'await') +>T31 : string | number +>Awaited : Awaited +>PromiseLike : PromiseLike +>Promise : Promise + +type T32 = Awaited>; // number (same as 'await') +>T32 : number +>Awaited : Awaited +>Awaited : Awaited + +type T33 = Awaited>>>; // number (same as 'await') +>T33 : number +>Awaited : Awaited +>Promise : Promise +>Awaited : Awaited +>Promise : Promise + diff --git a/tests/cases/compiler/awaitedOfT.ts b/tests/cases/compiler/awaitedOfT.ts new file mode 100644 index 0000000000000..6683946b286d9 --- /dev/null +++ b/tests/cases/compiler/awaitedOfT.ts @@ -0,0 +1,42 @@ +// @target: esnext +type T1 = Awaited; // number (same as 'await') +type T2 = Awaited>; // number (same as 'await') +type T3 = Awaited>>; // number (same as 'await') +type T4 = Awaited>>>; // number (same as 'await') +type T5 = Awaited>; // number (same as 'await') +type T6 = Awaited>>; // number (same as 'await') +type T7 = Awaited>>>; // number (same as 'await') +type T8 = Awaited>>; // number (same as 'await') +type T9 = Awaited>>; // number (same as 'await') +type T10 = Awaited<{ then: any; }>; // never (no way to know what this might resolve to, differs from 'await') +type T11 = Awaited<{ then: number; }>; // { then: number; } (same as 'await') +type T12 = Awaited<{ then(): void; }>; // never (no way to know what this might resolve to, error for 'await') +type T13 = Awaited<{ then(x: any): void; }>; // never (no way to know what this might resolve to, error for 'await') +type T14 = Awaited<{ then(x: number): void; }>; // never (cannot be resolved correctly, error for 'await') +type T15 = Awaited<{ then(x: () => void): void; }>; // never (no way to know what this might resolve to) +type T16 = Awaited<{ then(x: (y: any) => void): void; }>; // any (same as 'await') +type T17 = Awaited<{ then(x: (y: number) => void): void; }>; // number (same as 'await') +type T18 = Awaited<{ then(x: (y: { then: any; }) => void): void; }>; // { then: any; } (no recursive unwrap, differs from 'await') +type T19 = Awaited<{ then(x: (y: { then: number; }) => void): void; }>; // { then: number; } (no recursive unwrap, differs from 'await') +type T20 = Awaited<{ then(x: (y: { then(): void; }) => void): void; }>; // { then(): void; } (no recursive unwrap, differs from 'await') +type T21 = Awaited<{ then(x: (y: { then(x: any): void; }) => void): void; }>; // { then(x: any): void; } (no recursive unwrap, differs from 'await') +type T22 = Awaited<{ then(x: (y: { then(x: number): void; }) => void): void; }>; // { then(x: number): void; } (no recursive unwrap, differs from 'await') +type T23 = Awaited<{ then(x: (y: { then(x: () => void): void; }) => void): void; }>; // { then(x: () => void): void; } (no recursive unwrap, differs from 'await') +type T24 = Awaited<{ then(x: (y: { then(x: (y: any) => void): void; }) => void): void; }>; // { then(x: (y: any) => void): void; } (no recursive unwrap, differs from 'await') +type T25 = Awaited<{ then(x: (y: { then(x: (y: number) => void): void; }) => void): void; }>; // { then(x: (y: number) => void): void; } (no recursive unwrap, differs from 'await') + +// self recursive bad promise +type T26 = Awaited; // BadPromise (no recursive unwrap, differs from 'await') +interface BadPromise { then(cb: (value: BadPromise) => void): any; } + +// mutually recursive bad promises +type T27 = Awaited; // BadPromiseB (no recursive unwrap, differs from 'await') +interface BadPromiseA { then(cb: (value: BadPromiseB) => void): any; } +interface BadPromiseB { then(cb: (value: BadPromiseA) => void): any; } + +type T28 = Awaited; // never (same as 'await') +type T29 = Awaited>; // string | number (same as 'await') +type T30 = Awaited>; // number (same as 'await') +type T31 = Awaited | Promise>; // string | number (same as 'await') +type T32 = Awaited>; // number (same as 'await') +type T33 = Awaited>>>; // number (same as 'await') \ No newline at end of file