Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Nov 29, 2019
1 parent d93ff56 commit 887e72e
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/baselines/reference/asyncFunctionReturnType.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ async function fGenericIndexedTypeForPromiseOfKProp<TObj extends Obj, K extends
async function fGenericIndexedTypeForExplicitPromiseOfKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<TObj[K]> {
return Promise.resolve<TObj[K]>(obj[key]);
}

// #27711

async function fGeneric<T>(x: T) {
return x;
}
const expected: Promise<number> = fGeneric(undefined as Promise<number>);


//// [asyncFunctionReturnType.js]
Expand Down Expand Up @@ -173,3 +180,10 @@ function fGenericIndexedTypeForExplicitPromiseOfKProp(obj, key) {
return Promise.resolve(obj[key]);
});
}
// #27711
function fGeneric(x) {
return __awaiter(this, void 0, void 0, function* () {
return x;
});
}
const expected = fGeneric(undefined);
18 changes: 18 additions & 0 deletions tests/baselines/reference/asyncFunctionReturnType.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,21 @@ async function fGenericIndexedTypeForExplicitPromiseOfKProp<TObj extends Obj, K
>key : Symbol(key, Decl(asyncFunctionReturnType.ts, 72, 110))
}

// #27711

async function fGeneric<T>(x: T) {
>fGeneric : Symbol(fGeneric, Decl(asyncFunctionReturnType.ts, 74, 1))
>T : Symbol(T, Decl(asyncFunctionReturnType.ts, 78, 24))
>x : Symbol(x, Decl(asyncFunctionReturnType.ts, 78, 27))
>T : Symbol(T, Decl(asyncFunctionReturnType.ts, 78, 24))

return x;
>x : Symbol(x, Decl(asyncFunctionReturnType.ts, 78, 27))
}
const expected: Promise<number> = fGeneric(undefined as Promise<number>);
>expected : Symbol(expected, Decl(asyncFunctionReturnType.ts, 81, 5))
>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, --, --))
>fGeneric : Symbol(fGeneric, Decl(asyncFunctionReturnType.ts, 74, 1))
>undefined : Symbol(undefined)
>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, --, --))

16 changes: 16 additions & 0 deletions tests/baselines/reference/asyncFunctionReturnType.types
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,19 @@ async function fGenericIndexedTypeForExplicitPromiseOfKProp<TObj extends Obj, K
>key : K
}

// #27711

async function fGeneric<T>(x: T) {
>fGeneric : <T>(x: T) => Promise<Awaited<T>>
>x : T

return x;
>x : T
}
const expected: Promise<number> = fGeneric(undefined as Promise<number>);
>expected : Promise<number>
>fGeneric(undefined as Promise<number>) : Promise<number>
>fGeneric : <T>(x: T) => Promise<Awaited<T>>
>undefined as Promise<number> : Promise<number>
>undefined : undefined

3 changes: 3 additions & 0 deletions tests/baselines/reference/promiseType.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ 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));

const expected: undefined = undefined as Awaited<undefined>;


//// [promiseType.js]
Expand Down Expand Up @@ -440,3 +442,4 @@ 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));
const expected = undefined;
5 changes: 5 additions & 0 deletions tests/baselines/reference/promiseType.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -1089,3 +1089,8 @@ 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, --, --))

const expected: undefined = undefined as Awaited<undefined>;
>expected : Symbol(expected, Decl(promiseType.ts, 219, 5))
>undefined : Symbol(undefined)
>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --))

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

const expected: undefined = undefined as Awaited<undefined>;
>expected : undefined
>undefined as Awaited<undefined> : undefined
>undefined : undefined

7 changes: 7 additions & 0 deletions tests/cases/compiler/asyncFunctionReturnType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,10 @@ async function fGenericIndexedTypeForPromiseOfKProp<TObj extends Obj, K extends
async function fGenericIndexedTypeForExplicitPromiseOfKProp<TObj extends Obj, K extends keyof TObj>(obj: TObj, key: K): Promise<TObj[K]> {
return Promise.resolve<TObj[K]>(obj[key]);
}

// #27711

async function fGeneric<T>(x: T) {
return x;
}
const expected: Promise<number> = fGeneric(undefined as Promise<number>);
2 changes: 2 additions & 0 deletions tests/cases/compiler/promiseType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,5 @@ 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));

const expected: undefined = undefined as Awaited<undefined>;

0 comments on commit 887e72e

Please sign in to comment.