Skip to content

Commit e19aed3

Browse files
committed
Fix Awaited<T> for onfulfilled callbacks with more than one argument
1 parent d3d088f commit e19aed3

11 files changed

+227
-175
lines changed

Diff for: src/lib/es5.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ interface Promise<T> {
14951495
type Awaited<T> =
14961496
T extends null | undefined ? T : // special case for `null | undefined` when not in `--strictNullChecks` mode
14971497
T extends object & { then(onfulfilled: infer F): any } ? // `await` only unwraps object types with a callable `then`. Non-object types are not unwrapped
1498-
F extends ((value: infer V) => any) ? // if the argument to `then` is callable, extracts the argument
1498+
F extends ((value: infer V, ...args: any) => any) ? // if the argument to `then` is callable, extracts the first argument
14991499
Awaited<V> : // recursively unwrap the value
15001500
never : // the argument to `then` was not callable
15011501
T; // non-object or non-thenable

Diff for: tests/baselines/reference/awaitedType.errors.txt

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ tests/cases/compiler/awaitedType.ts(22,12): error TS2589: Type instantiation is
3030
~~~~~~~~~~~~~~~~~~~~
3131
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
3232

33+
// https://github.com/microsoft/TypeScript/issues/46934
34+
type T18 = Awaited<{ then(cb: (value: number, other: { }) => void)}>; // number
35+
3336
// https://github.com/microsoft/TypeScript/issues/33562
3437
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
3538
declare function MaybePromise<T>(value: T): MaybePromise<T>;

Diff for: tests/baselines/reference/awaitedType.js

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; }
2222
interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
2323
type T17 = Awaited<BadPromise1>; // error
2424

25+
// https://github.com/microsoft/TypeScript/issues/46934
26+
type T18 = Awaited<{ then(cb: (value: number, other: { }) => void)}>; // number
27+
2528
// https://github.com/microsoft/TypeScript/issues/33562
2629
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
2730
declare function MaybePromise<T>(value: T): MaybePromise<T>;

Diff for: tests/baselines/reference/awaitedType.symbols

+126-117
Large diffs are not rendered by default.

Diff for: tests/baselines/reference/awaitedType.types

+10-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
7575
type T17 = Awaited<BadPromise1>; // error
7676
>T17 : any
7777

78+
// https://github.com/microsoft/TypeScript/issues/46934
79+
type T18 = Awaited<{ then(cb: (value: number, other: { }) => void)}>; // number
80+
>T18 : number
81+
>then : (cb: (value: number, other: {}) => void) => any
82+
>cb : (value: number, other: {}) => void
83+
>value : number
84+
>other : {}
85+
7886
// https://github.com/microsoft/TypeScript/issues/33562
7987
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
8088
>MaybePromise : MaybePromise<T>
@@ -105,9 +113,9 @@ async function main() {
105113
] = await Promise.all([
106114
>await Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : [number, string, boolean]
107115
>Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : Promise<[number, string, boolean]>
108-
>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]>; }>; }
116+
>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]>; }>; }
109117
>Promise : PromiseConstructor
110-
>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]>; }>; }
118+
>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]>; }>; }
111119
>[ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ] : [number | Promise<1> | PromiseLike<1>, string | Promise<"2"> | PromiseLike<"2">, MaybePromise<true>]
112120

113121
MaybePromise(1),

Diff for: tests/baselines/reference/awaitedTypeStrictNull.errors.txt

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ tests/cases/compiler/awaitedTypeStrictNull.ts(22,12): error TS2589: Type instant
3030
~~~~~~~~~~~~~~~~~~~~
3131
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
3232

33+
// https://github.com/microsoft/TypeScript/issues/46934
34+
type T18 = Awaited<{ then(cb: (value: number, other: { }) => void)}>; // number
35+
3336
// https://github.com/microsoft/TypeScript/issues/33562
3437
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
3538
declare function MaybePromise<T>(value: T): MaybePromise<T>;

Diff for: tests/baselines/reference/awaitedTypeStrictNull.js

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; }
2222
interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
2323
type T17 = Awaited<BadPromise1>; // error
2424

25+
// https://github.com/microsoft/TypeScript/issues/46934
26+
type T18 = Awaited<{ then(cb: (value: number, other: { }) => void)}>; // number
27+
2528
// https://github.com/microsoft/TypeScript/issues/33562
2629
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
2730
declare function MaybePromise<T>(value: T): MaybePromise<T>;

Diff for: tests/baselines/reference/awaitedTypeStrictNull.symbols

+62-53
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,21 @@ type T12 = Awaited<Promise<Promise<number>>>;
6060

6161
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
6262
>T13 : Symbol(T13, Decl(awaitedTypeStrictNull.ts, 11, 45))
63-
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 54, 1))
63+
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 57, 1))
6464
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
6565
>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, --, --))
6666
>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, --, --))
6767

6868
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
6969
>T14 : Symbol(T14, Decl(awaitedTypeStrictNull.ts, 12, 107))
70-
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 54, 1))
70+
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 57, 1))
7171
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
7272
>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, --, --))
7373
>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, --, --))
7474

7575
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
7676
>T15 : Symbol(T15, Decl(awaitedTypeStrictNull.ts, 13, 117))
77-
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 54, 1))
77+
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 57, 1))
7878
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
7979
>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, --, --))
8080
>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, --, --))
@@ -110,111 +110,120 @@ type T17 = Awaited<BadPromise1>; // error
110110
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
111111
>BadPromise1 : Symbol(BadPromise1, Decl(awaitedTypeStrictNull.ts, 17, 31))
112112

113+
// https://github.com/microsoft/TypeScript/issues/46934
114+
type T18 = Awaited<{ then(cb: (value: number, other: { }) => void)}>; // number
115+
>T18 : Symbol(T18, Decl(awaitedTypeStrictNull.ts, 21, 32))
116+
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
117+
>then : Symbol(then, Decl(awaitedTypeStrictNull.ts, 24, 20))
118+
>cb : Symbol(cb, Decl(awaitedTypeStrictNull.ts, 24, 26))
119+
>value : Symbol(value, Decl(awaitedTypeStrictNull.ts, 24, 31))
120+
>other : Symbol(other, Decl(awaitedTypeStrictNull.ts, 24, 45))
121+
113122
// https://github.com/microsoft/TypeScript/issues/33562
114123
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
115-
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32))
116-
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 24, 18))
117-
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 24, 18))
124+
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 27, 54), Decl(awaitedTypeStrictNull.ts, 24, 69))
125+
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 27, 18))
126+
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 27, 18))
118127
>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, --, --))
119-
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 24, 18))
128+
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 27, 18))
120129
>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --))
121-
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 24, 18))
130+
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 27, 18))
122131

123132
declare function MaybePromise<T>(value: T): MaybePromise<T>;
124-
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32))
125-
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 25, 30))
126-
>value : Symbol(value, Decl(awaitedTypeStrictNull.ts, 25, 33))
127-
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 25, 30))
128-
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32))
129-
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 25, 30))
133+
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 27, 54), Decl(awaitedTypeStrictNull.ts, 24, 69))
134+
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 28, 30))
135+
>value : Symbol(value, Decl(awaitedTypeStrictNull.ts, 28, 33))
136+
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 28, 30))
137+
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 27, 54), Decl(awaitedTypeStrictNull.ts, 24, 69))
138+
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 28, 30))
130139

131140
async function main() {
132-
>main : Symbol(main, Decl(awaitedTypeStrictNull.ts, 25, 60))
141+
>main : Symbol(main, Decl(awaitedTypeStrictNull.ts, 28, 60))
133142

134143
let aaa: number;
135-
>aaa : Symbol(aaa, Decl(awaitedTypeStrictNull.ts, 28, 7))
144+
>aaa : Symbol(aaa, Decl(awaitedTypeStrictNull.ts, 31, 7))
136145

137146
let bbb: string;
138-
>bbb : Symbol(bbb, Decl(awaitedTypeStrictNull.ts, 29, 7))
147+
>bbb : Symbol(bbb, Decl(awaitedTypeStrictNull.ts, 32, 7))
139148

140149
[
141150
aaa,
142-
>aaa : Symbol(aaa, Decl(awaitedTypeStrictNull.ts, 28, 7))
151+
>aaa : Symbol(aaa, Decl(awaitedTypeStrictNull.ts, 31, 7))
143152

144153
bbb,
145-
>bbb : Symbol(bbb, Decl(awaitedTypeStrictNull.ts, 29, 7))
154+
>bbb : Symbol(bbb, Decl(awaitedTypeStrictNull.ts, 32, 7))
146155

147156
] = await Promise.all([
148157
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
149158
>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, --, --))
150159
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
151160

152161
MaybePromise(1),
153-
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32))
162+
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 27, 54), Decl(awaitedTypeStrictNull.ts, 24, 69))
154163

155164
MaybePromise('2'),
156-
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32))
165+
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 27, 54), Decl(awaitedTypeStrictNull.ts, 24, 69))
157166

158167
MaybePromise(true),
159-
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 24, 54), Decl(awaitedTypeStrictNull.ts, 21, 32))
168+
>MaybePromise : Symbol(MaybePromise, Decl(awaitedTypeStrictNull.ts, 27, 54), Decl(awaitedTypeStrictNull.ts, 24, 69))
160169

161170
])
162171
}
163172

164173
// https://github.com/microsoft/TypeScript/issues/45924
165174
class Api<D = {}> {
166-
>Api : Symbol(Api, Decl(awaitedTypeStrictNull.ts, 38, 1))
167-
>D : Symbol(D, Decl(awaitedTypeStrictNull.ts, 41, 10))
175+
>Api : Symbol(Api, Decl(awaitedTypeStrictNull.ts, 41, 1))
176+
>D : Symbol(D, Decl(awaitedTypeStrictNull.ts, 44, 10))
168177

169178
// Should result in `Promise<T>` instead of `Promise<Awaited<T>>`.
170179
async post<T = D>() { return this.request<T>(); }
171-
>post : Symbol(Api.post, Decl(awaitedTypeStrictNull.ts, 41, 19))
172-
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 43, 12))
173-
>D : Symbol(D, Decl(awaitedTypeStrictNull.ts, 41, 10))
174-
>this.request : Symbol(Api.request, Decl(awaitedTypeStrictNull.ts, 43, 50))
175-
>this : Symbol(Api, Decl(awaitedTypeStrictNull.ts, 38, 1))
176-
>request : Symbol(Api.request, Decl(awaitedTypeStrictNull.ts, 43, 50))
177-
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 43, 12))
180+
>post : Symbol(Api.post, Decl(awaitedTypeStrictNull.ts, 44, 19))
181+
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 46, 12))
182+
>D : Symbol(D, Decl(awaitedTypeStrictNull.ts, 44, 10))
183+
>this.request : Symbol(Api.request, Decl(awaitedTypeStrictNull.ts, 46, 50))
184+
>this : Symbol(Api, Decl(awaitedTypeStrictNull.ts, 41, 1))
185+
>request : Symbol(Api.request, Decl(awaitedTypeStrictNull.ts, 46, 50))
186+
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 46, 12))
178187

179188
async request<D>(): Promise<D> { throw new Error(); }
180-
>request : Symbol(Api.request, Decl(awaitedTypeStrictNull.ts, 43, 50))
181-
>D : Symbol(D, Decl(awaitedTypeStrictNull.ts, 44, 15))
189+
>request : Symbol(Api.request, Decl(awaitedTypeStrictNull.ts, 46, 50))
190+
>D : Symbol(D, Decl(awaitedTypeStrictNull.ts, 47, 15))
182191
>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, --, --))
183-
>D : Symbol(D, Decl(awaitedTypeStrictNull.ts, 44, 15))
192+
>D : Symbol(D, Decl(awaitedTypeStrictNull.ts, 47, 15))
184193
>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
185194
}
186195

187196
declare const api: Api;
188-
>api : Symbol(api, Decl(awaitedTypeStrictNull.ts, 47, 13))
189-
>Api : Symbol(Api, Decl(awaitedTypeStrictNull.ts, 38, 1))
197+
>api : Symbol(api, Decl(awaitedTypeStrictNull.ts, 50, 13))
198+
>Api : Symbol(Api, Decl(awaitedTypeStrictNull.ts, 41, 1))
190199

191200
interface Obj { x: number }
192-
>Obj : Symbol(Obj, Decl(awaitedTypeStrictNull.ts, 47, 23))
193-
>x : Symbol(Obj.x, Decl(awaitedTypeStrictNull.ts, 48, 15))
201+
>Obj : Symbol(Obj, Decl(awaitedTypeStrictNull.ts, 50, 23))
202+
>x : Symbol(Obj.x, Decl(awaitedTypeStrictNull.ts, 51, 15))
194203

195204
async function fn<T>(): Promise<T extends object ? { [K in keyof T]: Obj } : Obj> {
196-
>fn : Symbol(fn, Decl(awaitedTypeStrictNull.ts, 48, 27))
197-
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 50, 18))
205+
>fn : Symbol(fn, Decl(awaitedTypeStrictNull.ts, 51, 27))
206+
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 53, 18))
198207
>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, --, --))
199-
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 50, 18))
200-
>K : Symbol(K, Decl(awaitedTypeStrictNull.ts, 50, 54))
201-
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 50, 18))
202-
>Obj : Symbol(Obj, Decl(awaitedTypeStrictNull.ts, 47, 23))
203-
>Obj : Symbol(Obj, Decl(awaitedTypeStrictNull.ts, 47, 23))
208+
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 53, 18))
209+
>K : Symbol(K, Decl(awaitedTypeStrictNull.ts, 53, 54))
210+
>T : Symbol(T, Decl(awaitedTypeStrictNull.ts, 53, 18))
211+
>Obj : Symbol(Obj, Decl(awaitedTypeStrictNull.ts, 50, 23))
212+
>Obj : Symbol(Obj, Decl(awaitedTypeStrictNull.ts, 50, 23))
204213

205214
// Per #45924, this was failing due to incorrect inference both above and here.
206215
// Should not error.
207216
return api.post();
208-
>api.post : Symbol(Api.post, Decl(awaitedTypeStrictNull.ts, 41, 19))
209-
>api : Symbol(api, Decl(awaitedTypeStrictNull.ts, 47, 13))
210-
>post : Symbol(Api.post, Decl(awaitedTypeStrictNull.ts, 41, 19))
217+
>api.post : Symbol(Api.post, Decl(awaitedTypeStrictNull.ts, 44, 19))
218+
>api : Symbol(api, Decl(awaitedTypeStrictNull.ts, 50, 13))
219+
>post : Symbol(Api.post, Decl(awaitedTypeStrictNull.ts, 44, 19))
211220
}
212221

213222
// helps with tests where '.types' just prints out the type alias name
214223
type _Expect<TActual extends TExpected, TExpected> = TActual;
215-
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 54, 1))
216-
>TActual : Symbol(TActual, Decl(awaitedTypeStrictNull.ts, 57, 13))
217-
>TExpected : Symbol(TExpected, Decl(awaitedTypeStrictNull.ts, 57, 39))
218-
>TExpected : Symbol(TExpected, Decl(awaitedTypeStrictNull.ts, 57, 39))
219-
>TActual : Symbol(TActual, Decl(awaitedTypeStrictNull.ts, 57, 13))
224+
>_Expect : Symbol(_Expect, Decl(awaitedTypeStrictNull.ts, 57, 1))
225+
>TActual : Symbol(TActual, Decl(awaitedTypeStrictNull.ts, 60, 13))
226+
>TExpected : Symbol(TExpected, Decl(awaitedTypeStrictNull.ts, 60, 39))
227+
>TExpected : Symbol(TExpected, Decl(awaitedTypeStrictNull.ts, 60, 39))
228+
>TActual : Symbol(TActual, Decl(awaitedTypeStrictNull.ts, 60, 13))
220229

Diff for: tests/baselines/reference/awaitedTypeStrictNull.types

+10-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
7575
type T17 = Awaited<BadPromise1>; // error
7676
>T17 : any
7777

78+
// https://github.com/microsoft/TypeScript/issues/46934
79+
type T18 = Awaited<{ then(cb: (value: number, other: { }) => void)}>; // number
80+
>T18 : number
81+
>then : (cb: (value: number, other: {}) => void) => any
82+
>cb : (value: number, other: {}) => void
83+
>value : number
84+
>other : {}
85+
7886
// https://github.com/microsoft/TypeScript/issues/33562
7987
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
8088
>MaybePromise : MaybePromise<T>
@@ -105,9 +113,9 @@ async function main() {
105113
] = await Promise.all([
106114
>await Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : [number, string, boolean]
107115
>Promise.all([ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ]) : Promise<[number, string, boolean]>
108-
>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]>; }>; }
116+
>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]>; }>; }
109117
>Promise : PromiseConstructor
110-
>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]>; }>; }
118+
>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]>; }>; }
111119
>[ MaybePromise(1), MaybePromise('2'), MaybePromise(true), ] : [number | Promise<1> | PromiseLike<1>, string | Promise<"2"> | PromiseLike<"2">, MaybePromise<true>]
112120

113121
MaybePromise(1),

Diff for: tests/cases/compiler/awaitedType.ts

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ interface BadPromise1 { then(cb: (value: BadPromise2) => void): void; }
2424
interface BadPromise2 { then(cb: (value: BadPromise1) => void): void; }
2525
type T17 = Awaited<BadPromise1>; // error
2626

27+
// https://github.com/microsoft/TypeScript/issues/46934
28+
type T18 = Awaited<{ then(cb: (value: number, other: { }) => void)}>; // number
29+
2730
// https://github.com/microsoft/TypeScript/issues/33562
2831
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>
2932
declare function MaybePromise<T>(value: T): MaybePromise<T>;

0 commit comments

Comments
 (0)