Skip to content

Commit 9e9dd9c

Browse files
committed
Add tests
1 parent 6509e54 commit 9e9dd9c

File tree

4 files changed

+162
-0
lines changed

4 files changed

+162
-0
lines changed

tests/baselines/reference/promiseType.js

+32
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,30 @@ 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+
// #33074
232+
233+
Promise.resolve(x2);
234+
235+
// #33062
236+
237+
declare function f1(resolve: (value: Promise<number> | string) => void);
238+
new Promise(f1);
239+
240+
// #30390
241+
242+
declare function f2(): Promise<number> | string;
243+
p.then(f2);
220244

221245

222246
//// [promiseType.js]
@@ -440,3 +464,11 @@ const pc6 = p.then(() => Promise.reject("1"), () => { });
440464
const pc7 = p.then(() => Promise.reject("1"), () => { throw 1; });
441465
const pc8 = p.then(() => Promise.reject("1"), () => Promise.resolve(1));
442466
const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));
467+
// #27711
468+
const p2 = new Promise(() => { });
469+
// #28427
470+
Promise.all([x2]);
471+
// #33074
472+
Promise.resolve(x2);
473+
new Promise(f1);
474+
p.then(f2);

tests/baselines/reference/promiseType.symbols

+52
Original file line numberDiff line numberDiff line change
@@ -1089,3 +1089,55 @@ 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, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more)
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, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more)
1110+
>x2 : Symbol(x2, Decl(promiseType.ts, 223, 13))
1111+
1112+
// #33074
1113+
1114+
Promise.resolve(x2);
1115+
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
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+
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
1118+
>x2 : Symbol(x2, Decl(promiseType.ts, 223, 13))
1119+
1120+
// #33062
1121+
1122+
declare function f1(resolve: (value: Promise<number> | string) => void);
1123+
>f1 : Symbol(f1, Decl(promiseType.ts, 231, 20))
1124+
>resolve : Symbol(resolve, Decl(promiseType.ts, 235, 20))
1125+
>value : Symbol(value, Decl(promiseType.ts, 235, 30))
1126+
>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, --, --))
1127+
1128+
new Promise(f1);
1129+
>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, --, --))
1130+
>f1 : Symbol(f1, Decl(promiseType.ts, 231, 20))
1131+
1132+
// #30390
1133+
1134+
declare function f2(): Promise<number> | string;
1135+
>f2 : Symbol(f2, Decl(promiseType.ts, 236, 16))
1136+
>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, --, --))
1137+
1138+
p.then(f2);
1139+
>p.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
1140+
>p : Symbol(p, Decl(promiseType.ts, 0, 11))
1141+
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
1142+
>f2 : Symbol(f2, Decl(promiseType.ts, 236, 16))
1143+

tests/baselines/reference/promiseType.types

+54
Original file line numberDiff line numberDiff line change
@@ -1583,3 +1583,57 @@ 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, any, any, any, any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <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, any, any, any, any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <T extends readonly [any, any]>(values: T): Promise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>; <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+
// #33074
1608+
1609+
Promise.resolve(x2);
1610+
>Promise.resolve(x2) : Promise<string | number>
1611+
>Promise.resolve : { <T>(value: T): Promise<Awaited<T>>; (): Promise<void>; }
1612+
>Promise : PromiseConstructor
1613+
>resolve : { <T>(value: T): Promise<Awaited<T>>; (): Promise<void>; }
1614+
>x2 : string | Promise<number>
1615+
1616+
// #33062
1617+
1618+
declare function f1(resolve: (value: Promise<number> | string) => void);
1619+
>f1 : (resolve: (value: string | Promise<number>) => void) => any
1620+
>resolve : (value: string | Promise<number>) => void
1621+
>value : string | Promise<number>
1622+
1623+
new Promise(f1);
1624+
>new Promise(f1) : Promise<string | number>
1625+
>Promise : PromiseConstructor
1626+
>f1 : (resolve: (value: string | Promise<number>) => void) => any
1627+
1628+
// #30390
1629+
1630+
declare function f2(): Promise<number> | string;
1631+
>f2 : () => string | Promise<number>
1632+
1633+
p.then(f2);
1634+
>p.then(f2) : Promise<string | number>
1635+
>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)>
1636+
>p : Promise<boolean>
1637+
>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)>
1638+
>f2 : () => string | Promise<number>
1639+

tests/cases/compiler/promiseType.ts

+24
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,27 @@ 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+
// #33074
232+
233+
Promise.resolve(x2);
234+
235+
// #33062
236+
237+
declare function f1(resolve: (value: Promise<number> | string) => void);
238+
new Promise(f1);
239+
240+
// #30390
241+
242+
declare function f2(): Promise<number> | string;
243+
p.then(f2);

0 commit comments

Comments
 (0)