Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Oct 1, 2019
1 parent 6509e54 commit c0fdc66
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/baselines/reference/promiseType.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,26 @@ const pc6 = p.then(() => Promise.reject("1"), () => {});
const pc7 = p.then(() => Promise.reject("1"), () => {throw 1});
const pc8 = p.then(() => Promise.reject("1"), () => Promise.resolve(1));
const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));

declare const x2: Promise<number> | string;

// #28427

Promise.all([x2]);

// #33074

Promise.resolve(x2);

// #30390

declare function f1(): Promise<number> | string;
p.then(f1);

// #33062

declare function f2(resolve: (value: Promise<number> | string) => void);
new Promise(f2);


//// [promiseType.js]
Expand Down Expand Up @@ -440,3 +460,9 @@ const pc6 = p.then(() => Promise.reject("1"), () => { });
const pc7 = p.then(() => Promise.reject("1"), () => { throw 1; });
const pc8 = p.then(() => Promise.reject("1"), () => Promise.resolve(1));
const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));
// #28427
Promise.all([x2]);
// #33074
Promise.resolve(x2);
p.then(f1);
new Promise(f2);
44 changes: 44 additions & 0 deletions tests/baselines/reference/promiseType.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -1089,3 +1089,47 @@ const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));
>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, --, --))
>reject : Symbol(PromiseConstructor.reject, Decl(lib.es2015.promise.d.ts, --, --))

declare const x2: Promise<number> | string;
>x2 : Symbol(x2, Decl(promiseType.ts, 219, 13))
>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, --, --))

// #28427

Promise.all([x2]);
>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)
>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, --, --))
>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)
>x2 : Symbol(x2, Decl(promiseType.ts, 219, 13))

// #33074

Promise.resolve(x2);
>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>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, --, --))
>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --))
>x2 : Symbol(x2, Decl(promiseType.ts, 219, 13))

// #30390

declare function f1(): Promise<number> | string;
>f1 : Symbol(f1, Decl(promiseType.ts, 227, 20))
>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, --, --))

p.then(f1);
>p.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>p : Symbol(p, Decl(promiseType.ts, 0, 11))
>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --))
>f1 : Symbol(f1, Decl(promiseType.ts, 227, 20))

// #33062

declare function f2(resolve: (value: Promise<number> | string) => void);
>f2 : Symbol(f2, Decl(promiseType.ts, 232, 11))
>resolve : Symbol(resolve, Decl(promiseType.ts, 236, 20))
>value : Symbol(value, Decl(promiseType.ts, 236, 30))
>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, --, --))

new Promise(f2);
>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, --, --))
>f2 : Symbol(f2, Decl(promiseType.ts, 232, 11))

46 changes: 46 additions & 0 deletions tests/baselines/reference/promiseType.types
Original file line number Diff line number Diff line change
Expand Up @@ -1583,3 +1583,49 @@ const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));
>reject : <T = never>(reason?: any) => Promise<T>
>1 : 1

declare const x2: Promise<number> | string;
>x2 : string | Promise<number>

// #28427

Promise.all([x2]);
>Promise.all([x2]) : Promise<(string | number)[]>
>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]>; }>; }
>Promise : PromiseConstructor
>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]>; }>; }
>[x2] : (string | Promise<number>)[]
>x2 : string | Promise<number>

// #33074

Promise.resolve(x2);
>Promise.resolve(x2) : Promise<string | number>
>Promise.resolve : { <T>(value: T): Promise<Awaited<T>>; (): Promise<void>; }
>Promise : PromiseConstructor
>resolve : { <T>(value: T): Promise<Awaited<T>>; (): Promise<void>; }
>x2 : string | Promise<number>

// #30390

declare function f1(): Promise<number> | string;
>f1 : () => string | Promise<number>

p.then(f1);
>p.then(f1) : Promise<string | number>
>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)>
>p : Promise<boolean>
>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)>
>f1 : () => string | Promise<number>

// #33062

declare function f2(resolve: (value: Promise<number> | string) => void);
>f2 : (resolve: (value: string | Promise<number>) => void) => any
>resolve : (value: string | Promise<number>) => void
>value : string | Promise<number>

new Promise(f2);
>new Promise(f2) : Promise<string | number>
>Promise : PromiseConstructor
>f2 : (resolve: (value: string | Promise<number>) => void) => any

20 changes: 20 additions & 0 deletions tests/cases/compiler/promiseType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,23 @@ const pc6 = p.then(() => Promise.reject("1"), () => {});
const pc7 = p.then(() => Promise.reject("1"), () => {throw 1});
const pc8 = p.then(() => Promise.reject("1"), () => Promise.resolve(1));
const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1));

declare const x2: Promise<number> | string;

// #28427

Promise.all([x2]);

// #33074

Promise.resolve(x2);

// #30390

declare function f1(): Promise<number> | string;
p.then(f1);

// #33062

declare function f2(resolve: (value: Promise<number> | string) => void);
new Promise(f2);

0 comments on commit c0fdc66

Please sign in to comment.