Skip to content

Commit 500160b

Browse files
committed
Add tests
1 parent 09f78b1 commit 500160b

8 files changed

+120
-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 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 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 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 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

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

221231

222232
//// [promiseType.js]
@@ -440,3 +450,8 @@ const pc6 = p.then(() => Promise.reject("1"), () => { });
440450
const pc7 = p.then(() => Promise.reject("1"), () => { throw 1; });
441451
const pc8 = p.then(() => Promise.reject("1"), () => Promise.resolve(1));
442452
const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));
453+
// #28427
454+
Promise.all([undefined]);
455+
Promise.resolve(undefined);
456+
// #30390
457+
undefined.then(undefined);

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

+26
Original file line numberDiff line numberDiff line change
@@ -1089,3 +1089,29 @@ 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+
// #28427
1093+
1094+
Promise.all([undefined as Promise<number> | string]);
1095+
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
1096+
>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, --, --))
1097+
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
1098+
>undefined : Symbol(undefined)
1099+
>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, --, --))
1100+
1101+
Promise.resolve(undefined as Promise<number> | string);
1102+
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
1103+
>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, --, --))
1104+
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
1105+
>undefined : Symbol(undefined)
1106+
>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, --, --))
1107+
1108+
// #30390
1109+
1110+
(undefined as Promise<any>).then(undefined as () => Promise<number> | string);
1111+
>(undefined as Promise<any>).then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
1112+
>undefined : Symbol(undefined)
1113+
>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, --, --))
1114+
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
1115+
>undefined : Symbol(undefined)
1116+
>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, --, --))
1117+

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

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

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

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

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

0 commit comments

Comments
 (0)