From 7f1e42752e5c5f8173ae2da168ac7f35fe6bb12d Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Sat, 2 Nov 2019 12:46:16 -0700 Subject: [PATCH] Add tests --- .../reference/asyncFunctionReturnType.js | 14 ++++++++++++++ .../reference/asyncFunctionReturnType.symbols | 18 ++++++++++++++++++ .../reference/asyncFunctionReturnType.types | 16 ++++++++++++++++ tests/baselines/reference/promiseType.js | 3 +++ tests/baselines/reference/promiseType.symbols | 5 +++++ tests/baselines/reference/promiseType.types | 5 +++++ .../cases/compiler/asyncFunctionReturnType.ts | 7 +++++++ tests/cases/compiler/promiseType.ts | 2 ++ 8 files changed, 70 insertions(+) diff --git a/tests/baselines/reference/asyncFunctionReturnType.js b/tests/baselines/reference/asyncFunctionReturnType.js index 99d6b13c349ad..bd432fd7d8a67 100644 --- a/tests/baselines/reference/asyncFunctionReturnType.js +++ b/tests/baselines/reference/asyncFunctionReturnType.js @@ -74,6 +74,13 @@ async function fGenericIndexedTypeForPromiseOfKProp(obj: TObj, key: K): Promise { return Promise.resolve(obj[key]); } + +// #27711 + +async function fGeneric(x: T) { + return x; +} +const expected: Promise = fGeneric(undefined as Promise); //// [asyncFunctionReturnType.js] @@ -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); diff --git a/tests/baselines/reference/asyncFunctionReturnType.symbols b/tests/baselines/reference/asyncFunctionReturnType.symbols index cc930183d2210..7a106495b0afd 100644 --- a/tests/baselines/reference/asyncFunctionReturnType.symbols +++ b/tests/baselines/reference/asyncFunctionReturnType.symbols @@ -287,3 +287,21 @@ async function fGenericIndexedTypeForExplicitPromiseOfKPropkey : Symbol(key, Decl(asyncFunctionReturnType.ts, 72, 110)) } +// #27711 + +async function fGeneric(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 = fGeneric(undefined as Promise); +>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, --, --)) + diff --git a/tests/baselines/reference/asyncFunctionReturnType.types b/tests/baselines/reference/asyncFunctionReturnType.types index dd45a4bf6345a..a942588f43187 100644 --- a/tests/baselines/reference/asyncFunctionReturnType.types +++ b/tests/baselines/reference/asyncFunctionReturnType.types @@ -221,3 +221,19 @@ async function fGenericIndexedTypeForExplicitPromiseOfKPropkey : K } +// #27711 + +async function fGeneric(x: T) { +>fGeneric : (x: T) => Promise> +>x : T + + return x; +>x : T +} +const expected: Promise = fGeneric(undefined as Promise); +>expected : Promise +>fGeneric(undefined as Promise) : Promise +>fGeneric : (x: T) => Promise> +>undefined as Promise : Promise +>undefined : undefined + diff --git a/tests/baselines/reference/promiseType.js b/tests/baselines/reference/promiseType.js index 84d9d713b4810..6285d0415f358 100644 --- a/tests/baselines/reference/promiseType.js +++ b/tests/baselines/reference/promiseType.js @@ -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; //// [promiseType.js] @@ -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; diff --git a/tests/baselines/reference/promiseType.symbols b/tests/baselines/reference/promiseType.symbols index cec81cd7d8266..60589b5f4464b 100644 --- a/tests/baselines/reference/promiseType.symbols +++ b/tests/baselines/reference/promiseType.symbols @@ -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; +>expected : Symbol(expected, Decl(promiseType.ts, 219, 5)) +>undefined : Symbol(undefined) +>Awaited : Symbol(Awaited, Decl(lib.es5.d.ts, --, --)) + diff --git a/tests/baselines/reference/promiseType.types b/tests/baselines/reference/promiseType.types index dd20fb656ea5a..18e943c0ad032 100644 --- a/tests/baselines/reference/promiseType.types +++ b/tests/baselines/reference/promiseType.types @@ -1583,3 +1583,8 @@ const pc9 = p.then(() => Promise.reject("1"), () => Promise.reject(1)); >reject : (reason?: any) => Promise >1 : 1 +const expected: undefined = undefined as Awaited; +>expected : undefined +>undefined as Awaited : undefined +>undefined : undefined + diff --git a/tests/cases/compiler/asyncFunctionReturnType.ts b/tests/cases/compiler/asyncFunctionReturnType.ts index b8f8590d5228f..906b5fb6946cf 100644 --- a/tests/cases/compiler/asyncFunctionReturnType.ts +++ b/tests/cases/compiler/asyncFunctionReturnType.ts @@ -74,3 +74,10 @@ async function fGenericIndexedTypeForPromiseOfKProp(obj: TObj, key: K): Promise { return Promise.resolve(obj[key]); } + +// #27711 + +async function fGeneric(x: T) { + return x; +} +const expected: Promise = fGeneric(undefined as Promise); diff --git a/tests/cases/compiler/promiseType.ts b/tests/cases/compiler/promiseType.ts index ba4a7f6041396..db3fe4caa5553 100644 --- a/tests/cases/compiler/promiseType.ts +++ b/tests/cases/compiler/promiseType.ts @@ -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;