Skip to content

Commit

Permalink
Cherry-pick PR #46951 into release-4.5 (#47058)
Browse files Browse the repository at this point in the history
Component commits:
e19aed3 Fix Awaited<T> for onfulfilled callbacks with more than one argument

f4b3ef2 Merge branch 'main' into fix46934

Co-authored-by: Ron Buckton <rbuckton@microsoft.com>
  • Loading branch information
TypeScript Bot and rbuckton authored Dec 7, 2021
1 parent 49b1acc commit c1758b5
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 175 deletions.
2 changes: 1 addition & 1 deletion src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ interface Promise<T> {
type Awaited<T> =
T extends null | undefined ? T : // special case for `null | undefined` when not in `--strictNullChecks` mode
T extends object & { then(onfulfilled: infer F): any } ? // `await` only unwraps object types with a callable `then`. Non-object types are not unwrapped
F extends ((value: infer V) => any) ? // if the argument to `then` is callable, extracts the argument
F extends ((value: infer V, ...args: any) => any) ? // if the argument to `then` is callable, extracts the first argument
Awaited<V> : // recursively unwrap the value
never : // the argument to `then` was not callable
T; // non-object or non-thenable
Expand Down
3 changes: 3 additions & 0 deletions tests/baselines/reference/awaitedType.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ tests/cases/compiler/awaitedType.ts(22,12): error TS2589: Type instantiation is
~~~~~~~~~~~~~~~~~~~~
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.

// https://github.com/microsoft/TypeScript/issues/46934
type T18 = Awaited<{ then(cb: (value: number, other: { }) => void)}>; // number

// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
declare function MaybePromise<T>(value: T): MaybePromise<T>;
Expand Down
3 changes: 3 additions & 0 deletions tests/baselines/reference/awaitedType.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; }
interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
type T17 = Awaited<BadPromise1>; // error

// https://github.com/microsoft/TypeScript/issues/46934
type T18 = Awaited<{ then(cb: (value: number, other: { }) => void)}>; // number

// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
declare function MaybePromise<T>(value: T): MaybePromise<T>;
Expand Down
243 changes: 126 additions & 117 deletions tests/baselines/reference/awaitedType.symbols

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions tests/baselines/reference/awaitedType.types
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
type T17 = Awaited<BadPromise1>; // error
>T17 : any

// https://github.com/microsoft/TypeScript/issues/46934
type T18 = Awaited<{ then(cb: (value: number, other: { }) => void)}>; // number
>T18 : number
>then : (cb: (value: number, other: {}) => void) => any
>cb : (value: number, other: {}) => void
>value : number
>other : {}

// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
>MaybePromise : MaybePromise<T>
Expand Down Expand Up @@ -105,9 +113,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 : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>Promise.all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends [] | readonly unknown[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>Promise : PromiseConstructor
>all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends [] | readonly unknown[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>[ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ] : [number | Promise<1> | PromiseLike<1>, string | Promise<"2"> | PromiseLike<"2">, MaybePromise<true>]

MaybePromise(1),
Expand Down
3 changes: 3 additions & 0 deletions tests/baselines/reference/awaitedTypeStrictNull.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ tests/cases/compiler/awaitedTypeStrictNull.ts(22,12): error TS2589: Type instant
~~~~~~~~~~~~~~~~~~~~
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.

// https://github.com/microsoft/TypeScript/issues/46934
type T18 = Awaited<{ then(cb: (value: number, other: { }) => void)}>; // number

// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
declare function MaybePromise<T>(value: T): MaybePromise<T>;
Expand Down
3 changes: 3 additions & 0 deletions tests/baselines/reference/awaitedTypeStrictNull.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; }
interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
type T17 = Awaited<BadPromise1>; // error

// https://github.com/microsoft/TypeScript/issues/46934
type T18 = Awaited<{ then(cb: (value: number, other: { }) => void)}>; // number

// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
declare function MaybePromise<T>(value: T): MaybePromise<T>;
Expand Down
115 changes: 62 additions & 53 deletions tests/baselines/reference/awaitedTypeStrictNull.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@ type T12 = Awaited<Promise<Promise<number>>>;

type T13 = _Expect<Awaited<Promise<Promise<number>> | 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, 54, 1))
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 57, 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<Awaited<Promise<Promise<number>> | 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, 54, 1))
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 57, 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<Awaited<Promise<Promise<number>> | 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, 54, 1))
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 57, 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, --, --))
Expand Down Expand Up @@ -110,111 +110,120 @@ type T17 = Awaited<BadPromise1>; // error
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>BadPromise1 : Symbol(BadPromise1, Decl(awaitedTypeStrictNull.ts, 17, 31))

// https://github.com/microsoft/TypeScript/issues/46934
type T18 = Awaited<{ then(cb: (value: number, other: { }) => void)}>; // number
>T18 : Symbol(T18, Decl(awaitedTypeStrictNull.ts, 21, 32))
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
>then : Symbol(then, Decl(awaitedTypeStrictNull.ts, 24, 20))
>cb : Symbol(cb, Decl(awaitedTypeStrictNull.ts, 24, 26))
>value : Symbol(value, Decl(awaitedTypeStrictNull.ts, 24, 31))
>other : Symbol(other, Decl(awaitedTypeStrictNull.ts, 24, 45))

// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
>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))
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 27, 54), Decl(awaitedTypeStrictNull.ts, 24, 69))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 27, 18))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 27, 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))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 27, 18))
>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 24, 18))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 27, 18))

declare function MaybePromise<T>(value: T): MaybePromise<T>;
>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))
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 27, 54), Decl(awaitedTypeStrictNull.ts, 24, 69))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 28, 30))
>value : Symbol(value, Decl(awaitedTypeStrictNull.ts, 28, 33))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 28, 30))
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 27, 54), Decl(awaitedTypeStrictNull.ts, 24, 69))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 28, 30))

async function main() {
>main : Symbol(main, Decl(awaitedTypeStrictNull.ts, 25, 60))
>main : Symbol(main, Decl(awaitedTypeStrictNull.ts, 28, 60))

let aaa: number;
>aaa : Symbol(aaa, Decl(awaitedTypeStrictNull.ts, 28, 7))
>aaa : Symbol(aaa, Decl(awaitedTypeStrictNull.ts, 31, 7))

let bbb: string;
>bbb : Symbol(bbb, Decl(awaitedTypeStrictNull.ts, 29, 7))
>bbb : Symbol(bbb, Decl(awaitedTypeStrictNull.ts, 32, 7))

[
aaa,
>aaa : Symbol(aaa, Decl(awaitedTypeStrictNull.ts, 28, 7))
>aaa : Symbol(aaa, Decl(awaitedTypeStrictNull.ts, 31, 7))

bbb,
>bbb : Symbol(bbb, Decl(awaitedTypeStrictNull.ts, 29, 7))
>bbb : Symbol(bbb, Decl(awaitedTypeStrictNull.ts, 32, 7))

] = await Promise.all([
>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, --, --))

MaybePromise(1),
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32))
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 27, 54), Decl(awaitedTypeStrictNull.ts, 24, 69))

MaybePromise('2'),
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32))
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 27, 54), Decl(awaitedTypeStrictNull.ts, 24, 69))

MaybePromise(true),
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32))
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 27, 54), Decl(awaitedTypeStrictNull.ts, 24, 69))

])
}

// https://github.com/microsoft/TypeScript/issues/45924
class Api<D = {}> {
>Api : Symbol(Api, Decl(awaitedTypeStrictNull.ts, 38, 1))
>D : Symbol(D, Decl(awaitedTypeStrictNull.ts, 41, 10))
>Api : Symbol(Api, Decl(awaitedTypeStrictNull.ts, 41, 1))
>D : Symbol(D, Decl(awaitedTypeStrictNull.ts, 44, 10))

// Should result in `Promise<T>` instead of `Promise<Awaited<T>>`.
async post<T = D>() { return this.request<T>(); }
>post : Symbol(Api.post, Decl(awaitedTypeStrictNull.ts, 41, 19))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 43, 12))
>D : Symbol(D, Decl(awaitedTypeStrictNull.ts, 41, 10))
>this.request : Symbol(Api.request, Decl(awaitedTypeStrictNull.ts, 43, 50))
>this : Symbol(Api, Decl(awaitedTypeStrictNull.ts, 38, 1))
>request : Symbol(Api.request, Decl(awaitedTypeStrictNull.ts, 43, 50))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 43, 12))
>post : Symbol(Api.post, Decl(awaitedTypeStrictNull.ts, 44, 19))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 46, 12))
>D : Symbol(D, Decl(awaitedTypeStrictNull.ts, 44, 10))
>this.request : Symbol(Api.request, Decl(awaitedTypeStrictNull.ts, 46, 50))
>this : Symbol(Api, Decl(awaitedTypeStrictNull.ts, 41, 1))
>request : Symbol(Api.request, Decl(awaitedTypeStrictNull.ts, 46, 50))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 46, 12))

async request<D>(): Promise<D> { throw new Error(); }
>request : Symbol(Api.request, Decl(awaitedTypeStrictNull.ts, 43, 50))
>D : Symbol(D, Decl(awaitedTypeStrictNull.ts, 44, 15))
>request : Symbol(Api.request, Decl(awaitedTypeStrictNull.ts, 46, 50))
>D : Symbol(D, Decl(awaitedTypeStrictNull.ts, 47, 15))
>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, --, --))
>D : Symbol(D, Decl(awaitedTypeStrictNull.ts, 44, 15))
>D : Symbol(D, Decl(awaitedTypeStrictNull.ts, 47, 15))
>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
}

declare const api: Api;
>api : Symbol(api, Decl(awaitedTypeStrictNull.ts, 47, 13))
>Api : Symbol(Api, Decl(awaitedTypeStrictNull.ts, 38, 1))
>api : Symbol(api, Decl(awaitedTypeStrictNull.ts, 50, 13))
>Api : Symbol(Api, Decl(awaitedTypeStrictNull.ts, 41, 1))

interface Obj { x: number }
>Obj : Symbol(Obj, Decl(awaitedTypeStrictNull.ts, 47, 23))
>x : Symbol(Obj.x, Decl(awaitedTypeStrictNull.ts, 48, 15))
>Obj : Symbol(Obj, Decl(awaitedTypeStrictNull.ts, 50, 23))
>x : Symbol(Obj.x, Decl(awaitedTypeStrictNull.ts, 51, 15))

async function fn<T>(): Promise<T extends object ? { [K in keyof T]: Obj } : Obj> {
>fn : Symbol(fn, Decl(awaitedTypeStrictNull.ts, 48, 27))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 50, 18))
>fn : Symbol(fn, Decl(awaitedTypeStrictNull.ts, 51, 27))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 53, 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, 50, 18))
>K : Symbol(K, Decl(awaitedTypeStrictNull.ts, 50, 54))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 50, 18))
>Obj : Symbol(Obj, Decl(awaitedTypeStrictNull.ts, 47, 23))
>Obj : Symbol(Obj, Decl(awaitedTypeStrictNull.ts, 47, 23))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 53, 18))
>K : Symbol(K, Decl(awaitedTypeStrictNull.ts, 53, 54))
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 53, 18))
>Obj : Symbol(Obj, Decl(awaitedTypeStrictNull.ts, 50, 23))
>Obj : Symbol(Obj, Decl(awaitedTypeStrictNull.ts, 50, 23))

// Per #45924, this was failing due to incorrect inference both above and here.
// Should not error.
return api.post();
>api.post : Symbol(Api.post, Decl(awaitedTypeStrictNull.ts, 41, 19))
>api : Symbol(api, Decl(awaitedTypeStrictNull.ts, 47, 13))
>post : Symbol(Api.post, Decl(awaitedTypeStrictNull.ts, 41, 19))
>api.post : Symbol(Api.post, Decl(awaitedTypeStrictNull.ts, 44, 19))
>api : Symbol(api, Decl(awaitedTypeStrictNull.ts, 50, 13))
>post : Symbol(Api.post, Decl(awaitedTypeStrictNull.ts, 44, 19))
}

// helps with tests where '.types' just prints out the type alias name
type _Expect<TActual extends TExpected, TExpected> = TActual;
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 54, 1))
>TActual : Symbol(TActual, Decl(awaitedTypeStrictNull.ts, 57, 13))
>TExpected : Symbol(TExpected, Decl(awaitedTypeStrictNull.ts, 57, 39))
>TExpected : Symbol(TExpected, Decl(awaitedTypeStrictNull.ts, 57, 39))
>TActual : Symbol(TActual, Decl(awaitedTypeStrictNull.ts, 57, 13))
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 57, 1))
>TActual : Symbol(TActual, Decl(awaitedTypeStrictNull.ts, 60, 13))
>TExpected : Symbol(TExpected, Decl(awaitedTypeStrictNull.ts, 60, 39))
>TExpected : Symbol(TExpected, Decl(awaitedTypeStrictNull.ts, 60, 39))
>TActual : Symbol(TActual, Decl(awaitedTypeStrictNull.ts, 60, 13))

12 changes: 10 additions & 2 deletions tests/baselines/reference/awaitedTypeStrictNull.types
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
type T17 = Awaited<BadPromise1>; // error
>T17 : any

// https://github.com/microsoft/TypeScript/issues/46934
type T18 = Awaited<{ then(cb: (value: number, other: { }) => void)}>; // number
>T18 : number
>then : (cb: (value: number, other: {}) => void) => any
>cb : (value: number, other: {}) => void
>value : number
>other : {}

// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
>MaybePromise : MaybePromise<T>
Expand Down Expand Up @@ -105,9 +113,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 : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>Promise.all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends [] | readonly unknown[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>Promise : PromiseConstructor
>all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends readonly unknown[] | []>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>all : { <T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>; <T extends [] | readonly unknown[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
>[ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ] : [number | Promise<1> | PromiseLike<1>, string | Promise<"2"> | PromiseLike<"2">, MaybePromise<true>]

MaybePromise(1),
Expand Down
3 changes: 3 additions & 0 deletions tests/cases/compiler/awaitedType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; }
interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
type T17 = Awaited<BadPromise1>; // error

// https://github.com/microsoft/TypeScript/issues/46934
type T18 = Awaited<{ then(cb: (value: number, other: { }) => void)}>; // number

// https://github.com/microsoft/TypeScript/issues/33562
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
declare function MaybePromise<T>(value: T): MaybePromise<T>;
Expand Down
Loading

0 comments on commit c1758b5

Please sign in to comment.