Skip to content

Commit 034a6fc

Browse files
committed
Add tests
1 parent 42ed617 commit 034a6fc

12 files changed

+158
-8
lines changed

tests/baselines/reference/asyncFunctionReturnType.js

+14
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ async function fGenericIndexedTypeForPromiseOfKProp<TObj extends Obj, K extends
7474
async function fGenericIndexedTypeForExplicitPromiseOfKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<Awaited<TObj[K]>> {
7575
return Promise.resolve<TObj[K]>(obj[key]);
7676
}
77+
78+
// #27711
79+
80+
async function fGeneric<T>(x: T) {
81+
return x;
82+
}
83+
const expected: Promise<string> = fGeneric(undefined as Promise<string>);
7784

7885

7986
//// [asyncFunctionReturnType.js]
@@ -173,3 +180,10 @@ function fGenericIndexedTypeForExplicitPromiseOfKProp(obj, key) {
173180
return Promise.resolve(obj[key]);
174181
});
175182
}
183+
// #27711
184+
function fGeneric(x) {
185+
return __awaiter(this, void 0, void 0, function* () {
186+
return x;
187+
});
188+
}
189+
const expected = fGeneric(undefined);

tests/baselines/reference/asyncFunctionReturnType.symbols

+18
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,21 @@ async function fGenericIndexedTypeForExplicitPromiseOfKProp<TObj extends Obj, K
289289
>key : Symbol(key, Decl(asyncFunctionReturnType.ts, 72, 110))
290290
}
291291

292+
// #27711
293+
294+
async function fGeneric<T>(x: T) {
295+
>fGeneric : Symbol(fGeneric, Decl(asyncFunctionReturnType.ts, 74, 1))
296+
>T : Symbol(T, Decl(asyncFunctionReturnType.ts, 78, 24))
297+
>x : Symbol(x, Decl(asyncFunctionReturnType.ts, 78, 27))
298+
>T : Symbol(T, Decl(asyncFunctionReturnType.ts, 78, 24))
299+
300+
return x;
301+
>x : Symbol(x, Decl(asyncFunctionReturnType.ts, 78, 27))
302+
}
303+
const expected: Promise<string> = fGeneric(undefined as Promise<string>);
304+
>expected : Symbol(expected, Decl(asyncFunctionReturnType.ts, 81, 5))
305+
>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, --, --))
306+
>fGeneric : Symbol(fGeneric, Decl(asyncFunctionReturnType.ts, 74, 1))
307+
>undefined : Symbol(undefined)
308+
>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, --, --))
309+

tests/baselines/reference/asyncFunctionReturnType.types

+16
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,19 @@ async function fGenericIndexedTypeForExplicitPromiseOfKProp<TObj extends Obj, K
221221
>key : K
222222
}
223223

224+
// #27711
225+
226+
async function fGeneric<T>(x: T) {
227+
>fGeneric : <T>(x: T) => Promise<Awaited<T>>
228+
>x : T
229+
230+
return x;
231+
>x : T
232+
}
233+
const expected: Promise<string> = fGeneric(undefined as Promise<string>);
234+
>expected : Promise<string>
235+
>fGeneric(undefined as Promise<string>) : Promise<string>
236+
>fGeneric : <T>(x: T) => Promise<Awaited<T>>
237+
>undefined as Promise<string> : Promise<string>
238+
>undefined : undefined
239+

tests/baselines/reference/correctOrderOfPromiseMethod.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async function countEverything(): Promise<number> {
1515
const [resultA, resultB] = await Promise.all([
1616
providerA(),
1717
providerB(),
18-
] as const);
18+
]);
1919

2020
const dataA: A[] = resultA;
2121
const dataB: B[] = resultB;
@@ -24,6 +24,10 @@ async function countEverything(): Promise<number> {
2424
}
2525
return 0;
2626
}
27+
28+
// #31179
29+
30+
const expected: Promise<["a", "b", "c"]> = Promise.all(undefined as readonly ["a", "b", "c"]);
2731

2832

2933
//// [correctOrderOfPromiseMethod.js]
@@ -92,3 +96,5 @@ function countEverything() {
9296
});
9397
});
9498
}
99+
// #31179
100+
var expected = Promise.all(undefined);

tests/baselines/reference/correctOrderOfPromiseMethod.symbols

+11-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async function countEverything(): Promise<number> {
4343
providerB(),
4444
>providerB : Symbol(providerB, Decl(correctOrderOfPromiseMethod.ts, 11, 9))
4545

46-
] as const);
46+
]);
4747

4848
const dataA: A[] = resultA;
4949
>dataA : Symbol(dataA, Decl(correctOrderOfPromiseMethod.ts, 18, 9))
@@ -70,3 +70,13 @@ async function countEverything(): Promise<number> {
7070
return 0;
7171
}
7272

73+
// #31179
74+
75+
const expected: Promise<["a", "b", "c"]> = Promise.all(undefined as readonly ["a", "b", "c"]);
76+
>expected : Symbol(expected, Decl(correctOrderOfPromiseMethod.ts, 28, 5))
77+
>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, --, --))
78+
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
79+
>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, --, --))
80+
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
81+
>undefined : Symbol(undefined)
82+

tests/baselines/reference/correctOrderOfPromiseMethod.types

+15-5
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ async function countEverything(): Promise<number> {
2828
const [resultA, resultB] = await Promise.all([
2929
>resultA : A[]
3030
>resultB : B[]
31-
>await Promise.all([ providerA(), providerB(), ] as const) : [A[], B[]]
32-
>Promise.all([ providerA(), providerB(), ] as const) : Promise<[A[], B[]]>
31+
>await Promise.all([ providerA(), providerB(), ]) : [A[], B[]]
32+
>Promise.all([ providerA(), providerB(), ]) : Promise<[A[], B[]]>
3333
>Promise.all : { <TAll>(values: Iterable<TAll>): Promise<Awaited<TAll>[]>; <T extends readonly any[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
3434
>Promise : PromiseConstructor
3535
>all : { <TAll>(values: Iterable<TAll>): Promise<Awaited<TAll>[]>; <T extends readonly any[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
36-
>[ providerA(), providerB(), ] as const : readonly [Promise<A[]>, Promise<B[]>]
37-
>[ providerA(), providerB(), ] : readonly [Promise<A[]>, Promise<B[]>]
36+
>[ providerA(), providerB(), ] : [Promise<A[]>, Promise<B[]>]
3837

3938
providerA(),
4039
>providerA() : Promise<A[]>
@@ -44,7 +43,7 @@ async function countEverything(): Promise<number> {
4443
>providerB() : Promise<B[]>
4544
>providerB : () => Promise<B[]>
4645

47-
] as const);
46+
]);
4847

4948
const dataA: A[] = resultA;
5049
>dataA : A[]
@@ -72,3 +71,14 @@ async function countEverything(): Promise<number> {
7271
>0 : 0
7372
}
7473

74+
// #31179
75+
76+
const expected: Promise<["a", "b", "c"]> = Promise.all(undefined as readonly ["a", "b", "c"]);
77+
>expected : Promise<["a", "b", "c"]>
78+
>Promise.all(undefined as readonly ["a", "b", "c"]) : Promise<["a", "b", "c"]>
79+
>Promise.all : { <TAll>(values: Iterable<TAll>): Promise<Awaited<TAll>[]>; <T extends readonly any[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
80+
>Promise : PromiseConstructor
81+
>all : { <TAll>(values: Iterable<TAll>): Promise<Awaited<TAll>[]>; <T extends readonly any[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
82+
>undefined as readonly ["a", "b", "c"] : readonly ["a", "b", "c"]
83+
>undefined : undefined
84+

tests/baselines/reference/promiseType.js

+12
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ const pc6 = p.then(() => Promise.reject("1"), () => {});
217217
const pc7 = p.then(() => Promise.reject("1"), () => {throw 1});
218218
const pc8 = p.then(() => Promise.reject("1"), () => Promise.resolve(1));
219219
const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));
220+
221+
const expected: undefined = undefined as Awaited<undefined>;
222+
223+
// #28427
224+
225+
Promise.all([undefined as Promise<string> | number]);
226+
227+
Promise.resolve(undefined as Promise<string> | number);
220228

221229

222230
//// [promiseType.js]
@@ -440,3 +448,7 @@ const pc6 = p.then(() => Promise.reject("1"), () => { });
440448
const pc7 = p.then(() => Promise.reject("1"), () => { throw 1; });
441449
const pc8 = p.then(() => Promise.reject("1"), () => Promise.resolve(1));
442450
const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));
451+
const expected = undefined;
452+
// #28427
453+
Promise.all([undefined]);
454+
Promise.resolve(undefined);

tests/baselines/reference/promiseType.symbols

+21
Original file line numberDiff line numberDiff line change
@@ -1089,3 +1089,24 @@ const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));
10891089
>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, --, --))
10901090
>reject : Symbol(PromiseConstructor.reject, Decl(lib.es2015.promise.d.ts, --, --))
10911091

1092+
const expected: undefined = undefined as Awaited<undefined>;
1093+
>expected : Symbol(expected, Decl(promiseType.ts, 219, 5))
1094+
>undefined : Symbol(undefined)
1095+
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))
1096+
1097+
// #28427
1098+
1099+
Promise.all([undefined as Promise<string> | number]);
1100+
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
1101+
>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, --, --))
1102+
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
1103+
>undefined : Symbol(undefined)
1104+
>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, --, --))
1105+
1106+
Promise.resolve(undefined as Promise<string> | number);
1107+
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
1108+
>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, --, --))
1109+
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
1110+
>undefined : Symbol(undefined)
1111+
>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, --, --))
1112+

tests/baselines/reference/promiseType.types

+24
Original file line numberDiff line numberDiff line change
@@ -1583,3 +1583,27 @@ const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));
15831583
>reject : <T = never>(reason?: any) => Promise<T>
15841584
>1 : 1
15851585

1586+
const expected: undefined = undefined as Awaited<undefined>;
1587+
>expected : undefined
1588+
>undefined as Awaited<undefined> : undefined
1589+
>undefined : undefined
1590+
1591+
// #28427
1592+
1593+
Promise.all([undefined as Promise<string> | number]);
1594+
>Promise.all([undefined as Promise<string> | number]) : Promise<(string | number)[]>
1595+
>Promise.all : { <TAll>(values: Iterable<TAll>): Promise<Awaited<TAll>[]>; <T extends readonly any[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
1596+
>Promise : PromiseConstructor
1597+
>all : { <TAll>(values: Iterable<TAll>): Promise<Awaited<TAll>[]>; <T extends readonly any[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
1598+
>[undefined as Promise<string> | number] : (number | Promise<string>)[]
1599+
>undefined as Promise<string> | number : number | Promise<string>
1600+
>undefined : undefined
1601+
1602+
Promise.resolve(undefined as Promise<string> | number);
1603+
>Promise.resolve(undefined as Promise<string> | number) : Promise<string | number>
1604+
>Promise.resolve : { <T>(value: T): Promise<Awaited<T>>; (): Promise<void>; }
1605+
>Promise : PromiseConstructor
1606+
>resolve : { <T>(value: T): Promise<Awaited<T>>; (): Promise<void>; }
1607+
>undefined as Promise<string> | number : number | Promise<string>
1608+
>undefined : undefined
1609+

tests/cases/compiler/asyncFunctionReturnType.ts

+7
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,10 @@ async function fGenericIndexedTypeForPromiseOfKProp<TObj extends Obj, K extends
7474
async function fGenericIndexedTypeForExplicitPromiseOfKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<Awaited<TObj[K]>> {
7575
return Promise.resolve<TObj[K]>(obj[key]);
7676
}
77+
78+
// #27711
79+
80+
async function fGeneric<T>(x: T) {
81+
return x;
82+
}
83+
const expected: Promise<string> = fGeneric(undefined as Promise<string>);

tests/cases/compiler/correctOrderOfPromiseMethod.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function countEverything(): Promise<number> {
1717
const [resultA, resultB] = await Promise.all([
1818
providerA(),
1919
providerB(),
20-
] as const);
20+
]);
2121

2222
const dataA: A[] = resultA;
2323
const dataB: B[] = resultB;
@@ -26,3 +26,7 @@ async function countEverything(): Promise<number> {
2626
}
2727
return 0;
2828
}
29+
30+
// #31179
31+
32+
const expected: Promise<["a", "b", "c"]> = Promise.all(undefined as readonly ["a", "b", "c"]);

tests/cases/compiler/promiseType.ts

+8
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,11 @@ const pc6 = p.then(() => Promise.reject("1"), () => {});
217217
const pc7 = p.then(() => Promise.reject("1"), () => {throw 1});
218218
const pc8 = p.then(() => Promise.reject("1"), () => Promise.resolve(1));
219219
const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));
220+
221+
const expected: undefined = undefined as Awaited<undefined>;
222+
223+
// #28427
224+
225+
Promise.all([undefined as Promise<string> | number]);
226+
227+
Promise.resolve(undefined as Promise<string> | number);

0 commit comments

Comments
 (0)