Skip to content

Commit 497d816

Browse files
committed
Add tests
1 parent 6509e54 commit 497d816

File tree

4 files changed

+145
-0
lines changed

4 files changed

+145
-0
lines changed

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);

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, --, --), 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+
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+

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

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)