Skip to content

Commit 7224336

Browse files
committed
Add tests
1 parent 0c21d01 commit 7224336

8 files changed

+195
-8
lines changed

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

+9-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,11 @@ async function countEverything(): Promise<number> {
2424
}
2525
return 0;
2626
}
27+
28+
// #31179
29+
30+
const values = [1, 'a'] as const;
31+
const result: Promise<[1, 'a']> = Promise.all(values);
2732

2833

2934
//// [correctOrderOfPromiseMethod.js]
@@ -92,3 +97,6 @@ function countEverything() {
9297
});
9398
});
9499
}
100+
// #31179
101+
var values = [1, 'a'];
102+
var result = Promise.all(values);

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

+14-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,16 @@ async function countEverything(): Promise<number> {
7070
return 0;
7171
}
7272

73+
// #31179
74+
75+
const values = [1, 'a'] as const;
76+
>values : Symbol(values, Decl(correctOrderOfPromiseMethod.ts, 28, 5))
77+
78+
const result: Promise<[1, 'a']> = Promise.all(values);
79+
>result : Symbol(result, Decl(correctOrderOfPromiseMethod.ts, 29, 5))
80+
>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, --, --))
81+
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
82+
>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, --, --))
83+
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
84+
>values : Symbol(values, Decl(correctOrderOfPromiseMethod.ts, 28, 5))
85+

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

+21-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,20 @@ async function countEverything(): Promise<number> {
7271
>0 : 0
7372
}
7473

74+
// #31179
75+
76+
const values = [1, 'a'] as const;
77+
>values : readonly [1, "a"]
78+
>[1, 'a'] as const : readonly [1, "a"]
79+
>[1, 'a'] : readonly [1, "a"]
80+
>1 : 1
81+
>'a' : "a"
82+
83+
const result: Promise<[1, 'a']> = Promise.all(values);
84+
>result : Promise<[1, "a"]>
85+
>Promise.all(values) : Promise<[1, "a"]>
86+
>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]>; }>; }
87+
>Promise : PromiseConstructor
88+
>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]>; }>; }
89+
>values : readonly [1, "a"]
90+

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

+27
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,26 @@ 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+
// #27711
222+
223+
const p2: Promise<number> = new Promise<Promise<number>>(() => {});
224+
225+
declare const x2: Promise<number> | string;
226+
227+
// #28427
228+
229+
Promise.all([x2]);
230+
231+
Promise.resolve(x2);
232+
233+
declare function f1(resolve: (value: Promise<number> | string) => void);
234+
new Promise(f1);
235+
236+
// #30390
237+
238+
declare function f2(): Promise<number> | string;
239+
p.then(f2);
220240

221241

222242
//// [promiseType.js]
@@ -440,3 +460,10 @@ const pc6 = p.then(() => Promise.reject("1"), () => { });
440460
const pc7 = p.then(() => Promise.reject("1"), () => { throw 1; });
441461
const pc8 = p.then(() => Promise.reject("1"), () => Promise.resolve(1));
442462
const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));
463+
// #27711
464+
const p2 = new Promise(() => { });
465+
// #28427
466+
Promise.all([x2]);
467+
Promise.resolve(x2);
468+
new Promise(f1);
469+
p.then(f2);

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

+48
Original file line numberDiff line numberDiff line change
@@ -1089,3 +1089,51 @@ 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+
// #27711
1093+
1094+
const p2: Promise<number> = new Promise<Promise<number>>(() => {});
1095+
>p2 : Symbol(p2, Decl(promiseType.ts, 221, 5))
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+
>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, --, --))
1098+
>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, --, --))
1099+
1100+
declare const x2: Promise<number> | string;
1101+
>x2 : Symbol(x2, Decl(promiseType.ts, 223, 13))
1102+
>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, --, --))
1103+
1104+
// #28427
1105+
1106+
Promise.all([x2]);
1107+
>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.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+
>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
1110+
>x2 : Symbol(x2, Decl(promiseType.ts, 223, 13))
1111+
1112+
Promise.resolve(x2);
1113+
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
1114+
>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, --, --))
1115+
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
1116+
>x2 : Symbol(x2, Decl(promiseType.ts, 223, 13))
1117+
1118+
declare function f1(resolve: (value: Promise<number> | string) => void);
1119+
>f1 : Symbol(f1, Decl(promiseType.ts, 229, 20))
1120+
>resolve : Symbol(resolve, Decl(promiseType.ts, 231, 20))
1121+
>value : Symbol(value, Decl(promiseType.ts, 231, 30))
1122+
>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, --, --))
1123+
1124+
new Promise(f1);
1125+
>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, --, --))
1126+
>f1 : Symbol(f1, Decl(promiseType.ts, 229, 20))
1127+
1128+
// #30390
1129+
1130+
declare function f2(): Promise<number> | string;
1131+
>f2 : Symbol(f2, Decl(promiseType.ts, 232, 16))
1132+
>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, --, --))
1133+
1134+
p.then(f2);
1135+
>p.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
1136+
>p : Symbol(p, Decl(promiseType.ts, 0, 11))
1137+
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
1138+
>f2 : Symbol(f2, Decl(promiseType.ts, 232, 16))
1139+

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

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

1586+
// #27711
1587+
1588+
const p2: Promise<number> = new Promise<Promise<number>>(() => {});
1589+
>p2 : Promise<number>
1590+
>new Promise<Promise<number>>(() => {}) : Promise<number>
1591+
>Promise : PromiseConstructor
1592+
>() => {} : () => void
1593+
1594+
declare const x2: Promise<number> | string;
1595+
>x2 : string | Promise<number>
1596+
1597+
// #28427
1598+
1599+
Promise.all([x2]);
1600+
>Promise.all([x2]) : Promise<(string | number)[]>
1601+
>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]>; }>; }
1602+
>Promise : PromiseConstructor
1603+
>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]>; }>; }
1604+
>[x2] : (string | Promise<number>)[]
1605+
>x2 : string | Promise<number>
1606+
1607+
Promise.resolve(x2);
1608+
>Promise.resolve(x2) : Promise<string | number>
1609+
>Promise.resolve : { <T>(value: T): Promise<Awaited<T>>; (): Promise<void>; }
1610+
>Promise : PromiseConstructor
1611+
>resolve : { <T>(value: T): Promise<Awaited<T>>; (): Promise<void>; }
1612+
>x2 : string | Promise<number>
1613+
1614+
declare function f1(resolve: (value: Promise<number> | string) => void);
1615+
>f1 : (resolve: (value: string | Promise<number>) => void) => any
1616+
>resolve : (value: string | Promise<number>) => void
1617+
>value : string | Promise<number>
1618+
1619+
new Promise(f1);
1620+
>new Promise(f1) : Promise<string | number>
1621+
>Promise : PromiseConstructor
1622+
>f1 : (resolve: (value: string | Promise<number>) => void) => any
1623+
1624+
// #30390
1625+
1626+
declare function f2(): Promise<number> | string;
1627+
>f2 : () => string | Promise<number>
1628+
1629+
p.then(f2);
1630+
>p.then(f2) : Promise<string | number>
1631+
>p.then : <TResult1 = boolean, TResult2 = never>(onfulfilled?: (value: boolean) => TResult1, onrejected?: (reason: any) => TResult2) => Promise<(TResult1 extends PromiseLike<infer UResult1> ? UResult1 : TResult1) | (TResult2 extends PromiseLike<infer UResult2> ? UResult2 : TResult2)>
1632+
>p : Promise<boolean>
1633+
>then : <TResult1 = boolean, TResult2 = never>(onfulfilled?: (value: boolean) => TResult1, onrejected?: (reason: any) => TResult2) => Promise<(TResult1 extends PromiseLike<infer UResult1> ? UResult1 : TResult1) | (TResult2 extends PromiseLike<infer UResult2> ? UResult2 : TResult2)>
1634+
>f2 : () => string | Promise<number>
1635+

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

+6-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,8 @@ async function countEverything(): Promise<number> {
2626
}
2727
return 0;
2828
}
29+
30+
// #31179
31+
32+
const values = [1, 'a'] as const;
33+
const result: Promise<[1, 'a']> = Promise.all(values);

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

+20
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,23 @@ 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+
// #27711
222+
223+
const p2: Promise<number> = new Promise<Promise<number>>(() => {});
224+
225+
declare const x2: Promise<number> | string;
226+
227+
// #28427
228+
229+
Promise.all([x2]);
230+
231+
Promise.resolve(x2);
232+
233+
declare function f1(resolve: (value: Promise<number> | string) => void);
234+
new Promise(f1);
235+
236+
// #30390
237+
238+
declare function f2(): Promise<number> | string;
239+
p.then(f2);

0 commit comments

Comments
 (0)