Skip to content

Commit 52bc68c

Browse files
committed
Add tests
1 parent 852dda4 commit 52bc68c

8 files changed

+135
-8
lines changed

Diff for: 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 result: Promise<[0, 1, '']> = Promise.all(undefined as readonly [0, 1, '']);
2731

2832

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

Diff for: 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 result: Promise<[0, 1, '']> = Promise.all(undefined as readonly [0, 1, '']);
76+
>result : Symbol(result, 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+

Diff for: 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<(TAll extends undefined ? TAll : TAll extends PromiseLike<infer UAll> ? UAll : 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<(TAll extends undefined ? TAll : TAll extends PromiseLike<infer UAll> ? UAll : 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 result: Promise<[0, 1, '']> = Promise.all(undefined as readonly [0, 1, '']);
77+
>result : Promise<[0, 1, ""]>
78+
>Promise.all(undefined as readonly [0, 1, '']) : Promise<[0, 1, ""]>
79+
>Promise.all : { <TAll>(values: Iterable<TAll>): Promise<(TAll extends undefined ? TAll : TAll extends PromiseLike<infer UAll> ? UAll : 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<(TAll extends undefined ? TAll : TAll extends PromiseLike<infer UAll> ? UAll : TAll)[]>; <T extends readonly any[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
82+
>undefined as readonly [0, 1, ''] : readonly [0, 1, ""]
83+
>undefined : undefined
84+

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

+18
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,18 @@ 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 result: undefined = undefined as Awaited<undefined>;
222+
223+
// #28427
224+
225+
Promise.all([undefined as Promise<number> | string]);
226+
227+
Promise.resolve(undefined as Promise<number> | string);
228+
229+
// #30390
230+
231+
(undefined as Promise<any>).then(undefined as () => Promise<number> | string);
220232

221233

222234
//// [promiseType.js]
@@ -440,3 +452,9 @@ const pc6 = p.then(() => Promise.reject("1"), () => { });
440452
const pc7 = p.then(() => Promise.reject("1"), () => { throw 1; });
441453
const pc8 = p.then(() => Promise.reject("1"), () => Promise.resolve(1));
442454
const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));
455+
const result = undefined;
456+
// #28427
457+
Promise.all([undefined]);
458+
Promise.resolve(undefined);
459+
// #30390
460+
undefined.then(undefined);

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

+31
Original file line numberDiff line numberDiff line change
@@ -1089,3 +1089,34 @@ 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 result: undefined = undefined as Awaited<undefined>;
1093+
>result : Symbol(result, Decl(promiseType.ts, 219, 5))
1094+
>undefined : Symbol(undefined)
1095+
>Awaited : Symbol(Awaited, Decl(lib.es2015.promise.d.ts, --, --))
1096+
1097+
// #28427
1098+
1099+
Promise.all([undefined as Promise<number> | string]);
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<number> | string);
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+
1113+
// #30390
1114+
1115+
(undefined as Promise<any>).then(undefined as () => Promise<number> | string);
1116+
>(undefined as Promise<any>).then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
1117+
>undefined : Symbol(undefined)
1118+
>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, --, --))
1119+
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
1120+
>undefined : Symbol(undefined)
1121+
>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, --, --))
1122+

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

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

1586+
const result: undefined = undefined as Awaited<undefined>;
1587+
>result : undefined
1588+
>undefined as Awaited<undefined> : undefined
1589+
>undefined : undefined
1590+
1591+
// #28427
1592+
1593+
Promise.all([undefined as Promise<number> | string]);
1594+
>Promise.all([undefined as Promise<number> | string]) : Promise<(string | number)[]>
1595+
>Promise.all : { <TAll>(values: Iterable<TAll>): Promise<(TAll extends undefined ? TAll : TAll extends PromiseLike<infer UAll> ? UAll : 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<(TAll extends undefined ? TAll : TAll extends PromiseLike<infer UAll> ? UAll : TAll)[]>; <T extends readonly any[]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; }
1598+
>[undefined as Promise<number> | string] : (string | Promise<number>)[]
1599+
>undefined as Promise<number> | string : string | Promise<number>
1600+
>undefined : undefined
1601+
1602+
Promise.resolve(undefined as Promise<number> | string);
1603+
>Promise.resolve(undefined as Promise<number> | string) : 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<number> | string : string | Promise<number>
1608+
>undefined : undefined
1609+
1610+
// #30390
1611+
1612+
(undefined as Promise<any>).then(undefined as () => Promise<number> | string);
1613+
>(undefined as Promise<any>).then(undefined as () => Promise<number> | string) : Promise<string | number>
1614+
>(undefined as Promise<any>).then : <TResult1 = any, TResult2 = never>(onfulfilled?: (value: any) => TResult1, onrejected?: (reason: any) => TResult2) => Promise<(TResult1 extends undefined ? TResult1 : TResult1 extends PromiseLike<infer UResult1> ? UResult1 : TResult1) | (TResult2 extends undefined ? TResult2 : TResult2 extends PromiseLike<infer UResult2> ? UResult2 : TResult2)>
1615+
>(undefined as Promise<any>) : Promise<any>
1616+
>undefined as Promise<any> : Promise<any>
1617+
>undefined : undefined
1618+
>then : <TResult1 = any, TResult2 = never>(onfulfilled?: (value: any) => TResult1, onrejected?: (reason: any) => TResult2) => Promise<(TResult1 extends undefined ? TResult1 : TResult1 extends PromiseLike<infer UResult1> ? UResult1 : TResult1) | (TResult2 extends undefined ? TResult2 : TResult2 extends PromiseLike<infer UResult2> ? UResult2 : TResult2)>
1619+
>undefined as () => Promise<number> | string : () => string | Promise<number>
1620+
>undefined : undefined
1621+

Diff for: 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 result: Promise<[0, 1, '']> = Promise.all(undefined as readonly [0, 1, '']);

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

+12
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,15 @@ 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 result: undefined = undefined as Awaited<undefined>;
222+
223+
// #28427
224+
225+
Promise.all([undefined as Promise<number> | string]);
226+
227+
Promise.resolve(undefined as Promise<number> | string);
228+
229+
// #30390
230+
231+
(undefined as Promise<any>).then(undefined as () => Promise<number> | string);

0 commit comments

Comments
 (0)