From decc7c220e43777d6d5acfe32ccee5014a6ef94e Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 22 Dec 2016 14:05:03 -0800 Subject: [PATCH] Fix non-thenable check for IndexedAccess types --- src/compiler/checker.ts | 17 +- .../reference/asyncFunctionReturnType.js | 142 ++++++++- .../reference/asyncFunctionReturnType.symbols | 271 +++++++++++++++++ .../reference/asyncFunctionReturnType.types | 284 ++++++++++++++++++ .../cases/compiler/asyncFunctionReturnType.ts | 66 ++++ 5 files changed, 773 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6a1edbf3cc6..d0923be003b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3074,10 +3074,6 @@ namespace ts { return type && (type.flags & TypeFlags.Any) !== 0; } - function isTypeNever(type: Type) { - return type && (type.flags & TypeFlags.Never) !== 0; - } - // Return the type of a binding element parent. We check SymbolLinks first to see if a type has been // assigned by contextual typing. function getTypeForBindingElementParent(node: VariableLikeDeclaration) { @@ -16285,9 +16281,18 @@ namespace ts { } } - function checkNonThenableType(type: Type, location?: Node, message?: DiagnosticMessage) { + function isTypeOrConstraintAnyOrNever(type: Type) { + while (type.flags & TypeFlags.TypeVariable) { + const constraint = getConstraintOfTypeVariable(type); + if (!constraint) break; + type = getWidenedType(constraint); + } + return (type.flags & (TypeFlags.Any | TypeFlags.Never)) !== 0; + } + + function checkNonThenableType(type: Type, location?: Node, message?: DiagnosticMessage): Type { type = getWidenedType(type); - if (!isTypeAny(type) && !isTypeNever(type) && isTypeAssignableTo(type, getGlobalThenableType())) { + if (!isTypeOrConstraintAnyOrNever(type) && isTypeAssignableTo(type, getGlobalThenableType())) { if (location) { if (!message) { message = Diagnostics.Operand_for_await_does_not_have_a_valid_callable_then_member; diff --git a/tests/baselines/reference/asyncFunctionReturnType.js b/tests/baselines/reference/asyncFunctionReturnType.js index dcdead47c6b..6e39e72ae4c 100644 --- a/tests/baselines/reference/asyncFunctionReturnType.js +++ b/tests/baselines/reference/asyncFunctionReturnType.js @@ -8,7 +8,72 @@ async function fAsyncExplicit(): Promise<[number, boolean]> { // This is contextually typed as a tuple. return [1, true]; } - + +// https://github.com/Microsoft/TypeScript/issues/13128 +interface Obj { + stringProp: string; + anyProp: any; +} + +async function fIndexedTypeForStringProp(obj: Obj): Promise { + return obj.stringProp; +} + +async function fIndexedTypeForPromiseOfStringProp(obj: Obj): Promise { + return Promise.resolve(obj.stringProp); +} + +async function fIndexedTypeForExplicitPromiseOfStringProp(obj: Obj): Promise { + return Promise.resolve(obj.stringProp); +} + +async function fIndexedTypeForAnyProp(obj: Obj): Promise { + return obj.anyProp; +} + +async function fIndexedTypeForPromiseOfAnyProp(obj: Obj): Promise { + return Promise.resolve(obj.anyProp); +} + +async function fIndexedTypeForExplicitPromiseOfAnyProp(obj: Obj): Promise { + return Promise.resolve(obj.anyProp); +} + +async function fGenericIndexedTypeForStringProp(obj: TObj): Promise { + return obj.stringProp; +} + +async function fGenericIndexedTypeForPromiseOfStringProp(obj: TObj): Promise { + return Promise.resolve(obj.stringProp); +} + +async function fGenericIndexedTypeForExplicitPromiseOfStringProp(obj: TObj): Promise { + return Promise.resolve(obj.stringProp); +} + +async function fGenericIndexedTypeForAnyProp(obj: TObj): Promise { + return obj.anyProp; +} + +async function fGenericIndexedTypeForPromiseOfAnyProp(obj: TObj): Promise { + return Promise.resolve(obj.anyProp); +} + +async function fGenericIndexedTypeForExplicitPromiseOfAnyProp(obj: TObj): Promise { + return Promise.resolve(obj.anyProp); +} + +async function fGenericIndexedTypeForKProp(obj: TObj, key: K): Promise { + return obj[key]; +} + +async function fGenericIndexedTypeForPromiseOfKProp(obj: TObj, key: K): Promise { + return Promise.resolve(obj[key]); +} + +async function fGenericIndexedTypeForExplicitPromiseOfKProp(obj: TObj, key: K): Promise { + return Promise.resolve(obj[key]); +} //// [asyncFunctionReturnType.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { @@ -31,3 +96,78 @@ function fAsyncExplicit() { return [1, true]; }); } +function fIndexedTypeForStringProp(obj) { + return __awaiter(this, void 0, void 0, function* () { + return obj.stringProp; + }); +} +function fIndexedTypeForPromiseOfStringProp(obj) { + return __awaiter(this, void 0, void 0, function* () { + return Promise.resolve(obj.stringProp); + }); +} +function fIndexedTypeForExplicitPromiseOfStringProp(obj) { + return __awaiter(this, void 0, void 0, function* () { + return Promise.resolve(obj.stringProp); + }); +} +function fIndexedTypeForAnyProp(obj) { + return __awaiter(this, void 0, void 0, function* () { + return obj.anyProp; + }); +} +function fIndexedTypeForPromiseOfAnyProp(obj) { + return __awaiter(this, void 0, void 0, function* () { + return Promise.resolve(obj.anyProp); + }); +} +function fIndexedTypeForExplicitPromiseOfAnyProp(obj) { + return __awaiter(this, void 0, void 0, function* () { + return Promise.resolve(obj.anyProp); + }); +} +function fGenericIndexedTypeForStringProp(obj) { + return __awaiter(this, void 0, void 0, function* () { + return obj.stringProp; + }); +} +function fGenericIndexedTypeForPromiseOfStringProp(obj) { + return __awaiter(this, void 0, void 0, function* () { + return Promise.resolve(obj.stringProp); + }); +} +function fGenericIndexedTypeForExplicitPromiseOfStringProp(obj) { + return __awaiter(this, void 0, void 0, function* () { + return Promise.resolve(obj.stringProp); + }); +} +function fGenericIndexedTypeForAnyProp(obj) { + return __awaiter(this, void 0, void 0, function* () { + return obj.anyProp; + }); +} +function fGenericIndexedTypeForPromiseOfAnyProp(obj) { + return __awaiter(this, void 0, void 0, function* () { + return Promise.resolve(obj.anyProp); + }); +} +function fGenericIndexedTypeForExplicitPromiseOfAnyProp(obj) { + return __awaiter(this, void 0, void 0, function* () { + return Promise.resolve(obj.anyProp); + }); +} +function fGenericIndexedTypeForKProp(obj, key) { + return __awaiter(this, void 0, void 0, function* () { + return obj[key]; + }); +} +function fGenericIndexedTypeForPromiseOfKProp(obj, key) { + return __awaiter(this, void 0, void 0, function* () { + return Promise.resolve(obj[key]); + }); +} +function fGenericIndexedTypeForExplicitPromiseOfKProp(obj, key) { + return __awaiter(this, void 0, void 0, function* () { + return Promise.resolve(obj[key]); + }); +} diff --git a/tests/baselines/reference/asyncFunctionReturnType.symbols b/tests/baselines/reference/asyncFunctionReturnType.symbols index 75e456b6a8b..d5aa71c9e51 100644 --- a/tests/baselines/reference/asyncFunctionReturnType.symbols +++ b/tests/baselines/reference/asyncFunctionReturnType.symbols @@ -14,3 +14,274 @@ async function fAsyncExplicit(): Promise<[number, boolean]> { return [1, true]; } +// https://github.com/Microsoft/TypeScript/issues/13128 +interface Obj { +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) + + stringProp: string; +>stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15)) + + anyProp: any; +>anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23)) +} + +async function fIndexedTypeForStringProp(obj: Obj): Promise { +>fIndexedTypeForStringProp : Symbol(fIndexedTypeForStringProp, Decl(asyncFunctionReturnType.ts, 14, 1)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 16, 41)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) + + return obj.stringProp; +>obj.stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 16, 41)) +>stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15)) +} + +async function fIndexedTypeForPromiseOfStringProp(obj: Obj): Promise { +>fIndexedTypeForPromiseOfStringProp : Symbol(fIndexedTypeForPromiseOfStringProp, Decl(asyncFunctionReturnType.ts, 18, 1)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 20, 50)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) + + return Promise.resolve(obj.stringProp); +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>obj.stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 20, 50)) +>stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15)) +} + +async function fIndexedTypeForExplicitPromiseOfStringProp(obj: Obj): Promise { +>fIndexedTypeForExplicitPromiseOfStringProp : Symbol(fIndexedTypeForExplicitPromiseOfStringProp, Decl(asyncFunctionReturnType.ts, 22, 1)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 24, 58)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) + + return Promise.resolve(obj.stringProp); +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>obj.stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 24, 58)) +>stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15)) +} + +async function fIndexedTypeForAnyProp(obj: Obj): Promise { +>fIndexedTypeForAnyProp : Symbol(fIndexedTypeForAnyProp, Decl(asyncFunctionReturnType.ts, 26, 1)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 28, 38)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) + + return obj.anyProp; +>obj.anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 28, 38)) +>anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23)) +} + +async function fIndexedTypeForPromiseOfAnyProp(obj: Obj): Promise { +>fIndexedTypeForPromiseOfAnyProp : Symbol(fIndexedTypeForPromiseOfAnyProp, Decl(asyncFunctionReturnType.ts, 30, 1)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 32, 47)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) + + return Promise.resolve(obj.anyProp); +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>obj.anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 32, 47)) +>anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23)) +} + +async function fIndexedTypeForExplicitPromiseOfAnyProp(obj: Obj): Promise { +>fIndexedTypeForExplicitPromiseOfAnyProp : Symbol(fIndexedTypeForExplicitPromiseOfAnyProp, Decl(asyncFunctionReturnType.ts, 34, 1)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 36, 55)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) + + return Promise.resolve(obj.anyProp); +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>obj.anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 36, 55)) +>anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23)) +} + +async function fGenericIndexedTypeForStringProp(obj: TObj): Promise { +>fGenericIndexedTypeForStringProp : Symbol(fGenericIndexedTypeForStringProp, Decl(asyncFunctionReturnType.ts, 38, 1)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 40, 48)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 40, 66)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 40, 48)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 40, 48)) + + return obj.stringProp; +>obj.stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 40, 66)) +>stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15)) +} + +async function fGenericIndexedTypeForPromiseOfStringProp(obj: TObj): Promise { +>fGenericIndexedTypeForPromiseOfStringProp : Symbol(fGenericIndexedTypeForPromiseOfStringProp, Decl(asyncFunctionReturnType.ts, 42, 1)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 44, 57)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 44, 75)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 44, 57)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 44, 57)) + + return Promise.resolve(obj.stringProp); +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>obj.stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 44, 75)) +>stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15)) +} + +async function fGenericIndexedTypeForExplicitPromiseOfStringProp(obj: TObj): Promise { +>fGenericIndexedTypeForExplicitPromiseOfStringProp : Symbol(fGenericIndexedTypeForExplicitPromiseOfStringProp, Decl(asyncFunctionReturnType.ts, 46, 1)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 48, 65)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 48, 83)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 48, 65)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 48, 65)) + + return Promise.resolve(obj.stringProp); +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 48, 65)) +>obj.stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 48, 83)) +>stringProp : Symbol(Obj.stringProp, Decl(asyncFunctionReturnType.ts, 11, 15)) +} + +async function fGenericIndexedTypeForAnyProp(obj: TObj): Promise { +>fGenericIndexedTypeForAnyProp : Symbol(fGenericIndexedTypeForAnyProp, Decl(asyncFunctionReturnType.ts, 50, 1)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 52, 45)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 52, 63)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 52, 45)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 52, 45)) + + return obj.anyProp; +>obj.anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 52, 63)) +>anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23)) +} + +async function fGenericIndexedTypeForPromiseOfAnyProp(obj: TObj): Promise { +>fGenericIndexedTypeForPromiseOfAnyProp : Symbol(fGenericIndexedTypeForPromiseOfAnyProp, Decl(asyncFunctionReturnType.ts, 54, 1)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 56, 54)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 56, 72)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 56, 54)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 56, 54)) + + return Promise.resolve(obj.anyProp); +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>obj.anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 56, 72)) +>anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23)) +} + +async function fGenericIndexedTypeForExplicitPromiseOfAnyProp(obj: TObj): Promise { +>fGenericIndexedTypeForExplicitPromiseOfAnyProp : Symbol(fGenericIndexedTypeForExplicitPromiseOfAnyProp, Decl(asyncFunctionReturnType.ts, 58, 1)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 60, 62)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 60, 80)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 60, 62)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 60, 62)) + + return Promise.resolve(obj.anyProp); +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 60, 62)) +>obj.anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 60, 80)) +>anyProp : Symbol(Obj.anyProp, Decl(asyncFunctionReturnType.ts, 12, 23)) +} + +async function fGenericIndexedTypeForKProp(obj: TObj, key: K): Promise { +>fGenericIndexedTypeForKProp : Symbol(fGenericIndexedTypeForKProp, Decl(asyncFunctionReturnType.ts, 62, 1)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 64, 43)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 64, 60)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 64, 43)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 64, 83)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 64, 43)) +>key : Symbol(key, Decl(asyncFunctionReturnType.ts, 64, 93)) +>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 64, 60)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 64, 43)) +>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 64, 60)) + + return obj[key]; +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 64, 83)) +>key : Symbol(key, Decl(asyncFunctionReturnType.ts, 64, 93)) +} + +async function fGenericIndexedTypeForPromiseOfKProp(obj: TObj, key: K): Promise { +>fGenericIndexedTypeForPromiseOfKProp : Symbol(fGenericIndexedTypeForPromiseOfKProp, Decl(asyncFunctionReturnType.ts, 66, 1)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 68, 52)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 68, 69)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 68, 52)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 68, 92)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 68, 52)) +>key : Symbol(key, Decl(asyncFunctionReturnType.ts, 68, 102)) +>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 68, 69)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 68, 52)) +>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 68, 69)) + + return Promise.resolve(obj[key]); +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 68, 92)) +>key : Symbol(key, Decl(asyncFunctionReturnType.ts, 68, 102)) +} + +async function fGenericIndexedTypeForExplicitPromiseOfKProp(obj: TObj, key: K): Promise { +>fGenericIndexedTypeForExplicitPromiseOfKProp : Symbol(fGenericIndexedTypeForExplicitPromiseOfKProp, Decl(asyncFunctionReturnType.ts, 70, 1)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 72, 60)) +>Obj : Symbol(Obj, Decl(asyncFunctionReturnType.ts, 8, 1)) +>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 72, 77)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 72, 60)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 72, 100)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 72, 60)) +>key : Symbol(key, Decl(asyncFunctionReturnType.ts, 72, 110)) +>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 72, 77)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 72, 60)) +>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 72, 77)) + + return Promise.resolve(obj[key]); +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>TObj : Symbol(TObj, Decl(asyncFunctionReturnType.ts, 72, 60)) +>K : Symbol(K, Decl(asyncFunctionReturnType.ts, 72, 77)) +>obj : Symbol(obj, Decl(asyncFunctionReturnType.ts, 72, 100)) +>key : Symbol(key, Decl(asyncFunctionReturnType.ts, 72, 110)) +} diff --git a/tests/baselines/reference/asyncFunctionReturnType.types b/tests/baselines/reference/asyncFunctionReturnType.types index db9f8e42d52..d1dab14ba87 100644 --- a/tests/baselines/reference/asyncFunctionReturnType.types +++ b/tests/baselines/reference/asyncFunctionReturnType.types @@ -20,3 +20,287 @@ async function fAsyncExplicit(): Promise<[number, boolean]> { >true : true } +// https://github.com/Microsoft/TypeScript/issues/13128 +interface Obj { +>Obj : Obj + + stringProp: string; +>stringProp : string + + anyProp: any; +>anyProp : any +} + +async function fIndexedTypeForStringProp(obj: Obj): Promise { +>fIndexedTypeForStringProp : (obj: Obj) => Promise +>obj : Obj +>Obj : Obj +>Promise : Promise +>Obj : Obj + + return obj.stringProp; +>obj.stringProp : string +>obj : Obj +>stringProp : string +} + +async function fIndexedTypeForPromiseOfStringProp(obj: Obj): Promise { +>fIndexedTypeForPromiseOfStringProp : (obj: Obj) => Promise +>obj : Obj +>Obj : Obj +>Promise : Promise +>Obj : Obj + + return Promise.resolve(obj.stringProp); +>Promise.resolve(obj.stringProp) : Promise +>Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>obj.stringProp : string +>obj : Obj +>stringProp : string +} + +async function fIndexedTypeForExplicitPromiseOfStringProp(obj: Obj): Promise { +>fIndexedTypeForExplicitPromiseOfStringProp : (obj: Obj) => Promise +>obj : Obj +>Obj : Obj +>Promise : Promise +>Obj : Obj + + return Promise.resolve(obj.stringProp); +>Promise.resolve(obj.stringProp) : Promise +>Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Obj : Obj +>obj.stringProp : string +>obj : Obj +>stringProp : string +} + +async function fIndexedTypeForAnyProp(obj: Obj): Promise { +>fIndexedTypeForAnyProp : (obj: Obj) => Promise +>obj : Obj +>Obj : Obj +>Promise : Promise +>Obj : Obj + + return obj.anyProp; +>obj.anyProp : any +>obj : Obj +>anyProp : any +} + +async function fIndexedTypeForPromiseOfAnyProp(obj: Obj): Promise { +>fIndexedTypeForPromiseOfAnyProp : (obj: Obj) => Promise +>obj : Obj +>Obj : Obj +>Promise : Promise +>Obj : Obj + + return Promise.resolve(obj.anyProp); +>Promise.resolve(obj.anyProp) : Promise +>Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>obj.anyProp : any +>obj : Obj +>anyProp : any +} + +async function fIndexedTypeForExplicitPromiseOfAnyProp(obj: Obj): Promise { +>fIndexedTypeForExplicitPromiseOfAnyProp : (obj: Obj) => Promise +>obj : Obj +>Obj : Obj +>Promise : Promise +>Obj : Obj + + return Promise.resolve(obj.anyProp); +>Promise.resolve(obj.anyProp) : Promise +>Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Obj : Obj +>obj.anyProp : any +>obj : Obj +>anyProp : any +} + +async function fGenericIndexedTypeForStringProp(obj: TObj): Promise { +>fGenericIndexedTypeForStringProp : (obj: TObj) => Promise +>TObj : TObj +>Obj : Obj +>obj : TObj +>TObj : TObj +>Promise : Promise +>TObj : TObj + + return obj.stringProp; +>obj.stringProp : string +>obj : TObj +>stringProp : string +} + +async function fGenericIndexedTypeForPromiseOfStringProp(obj: TObj): Promise { +>fGenericIndexedTypeForPromiseOfStringProp : (obj: TObj) => Promise +>TObj : TObj +>Obj : Obj +>obj : TObj +>TObj : TObj +>Promise : Promise +>TObj : TObj + + return Promise.resolve(obj.stringProp); +>Promise.resolve(obj.stringProp) : Promise +>Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>obj.stringProp : string +>obj : TObj +>stringProp : string +} + +async function fGenericIndexedTypeForExplicitPromiseOfStringProp(obj: TObj): Promise { +>fGenericIndexedTypeForExplicitPromiseOfStringProp : (obj: TObj) => Promise +>TObj : TObj +>Obj : Obj +>obj : TObj +>TObj : TObj +>Promise : Promise +>TObj : TObj + + return Promise.resolve(obj.stringProp); +>Promise.resolve(obj.stringProp) : Promise +>Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>TObj : TObj +>obj.stringProp : string +>obj : TObj +>stringProp : string +} + +async function fGenericIndexedTypeForAnyProp(obj: TObj): Promise { +>fGenericIndexedTypeForAnyProp : (obj: TObj) => Promise +>TObj : TObj +>Obj : Obj +>obj : TObj +>TObj : TObj +>Promise : Promise +>TObj : TObj + + return obj.anyProp; +>obj.anyProp : any +>obj : TObj +>anyProp : any +} + +async function fGenericIndexedTypeForPromiseOfAnyProp(obj: TObj): Promise { +>fGenericIndexedTypeForPromiseOfAnyProp : (obj: TObj) => Promise +>TObj : TObj +>Obj : Obj +>obj : TObj +>TObj : TObj +>Promise : Promise +>TObj : TObj + + return Promise.resolve(obj.anyProp); +>Promise.resolve(obj.anyProp) : Promise +>Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>obj.anyProp : any +>obj : TObj +>anyProp : any +} + +async function fGenericIndexedTypeForExplicitPromiseOfAnyProp(obj: TObj): Promise { +>fGenericIndexedTypeForExplicitPromiseOfAnyProp : (obj: TObj) => Promise +>TObj : TObj +>Obj : Obj +>obj : TObj +>TObj : TObj +>Promise : Promise +>TObj : TObj + + return Promise.resolve(obj.anyProp); +>Promise.resolve(obj.anyProp) : Promise +>Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>TObj : TObj +>obj.anyProp : any +>obj : TObj +>anyProp : any +} + +async function fGenericIndexedTypeForKProp(obj: TObj, key: K): Promise { +>fGenericIndexedTypeForKProp : (obj: TObj, key: K) => Promise +>TObj : TObj +>Obj : Obj +>K : K +>TObj : TObj +>obj : TObj +>TObj : TObj +>key : K +>K : K +>Promise : Promise +>TObj : TObj +>K : K + + return obj[key]; +>obj[key] : TObj[K] +>obj : TObj +>key : K +} + +async function fGenericIndexedTypeForPromiseOfKProp(obj: TObj, key: K): Promise { +>fGenericIndexedTypeForPromiseOfKProp : (obj: TObj, key: K) => Promise +>TObj : TObj +>Obj : Obj +>K : K +>TObj : TObj +>obj : TObj +>TObj : TObj +>key : K +>K : K +>Promise : Promise +>TObj : TObj +>K : K + + return Promise.resolve(obj[key]); +>Promise.resolve(obj[key]) : Promise +>Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>obj[key] : TObj[K] +>obj : TObj +>key : K +} + +async function fGenericIndexedTypeForExplicitPromiseOfKProp(obj: TObj, key: K): Promise { +>fGenericIndexedTypeForExplicitPromiseOfKProp : (obj: TObj, key: K) => Promise +>TObj : TObj +>Obj : Obj +>K : K +>TObj : TObj +>obj : TObj +>TObj : TObj +>key : K +>K : K +>Promise : Promise +>TObj : TObj +>K : K + + return Promise.resolve(obj[key]); +>Promise.resolve(obj[key]) : Promise +>Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>Promise : PromiseConstructor +>resolve : { (value: T | PromiseLike): Promise; (): Promise; } +>TObj : TObj +>K : K +>obj[key] : TObj[K] +>obj : TObj +>key : K +} diff --git a/tests/cases/compiler/asyncFunctionReturnType.ts b/tests/cases/compiler/asyncFunctionReturnType.ts index a1bcde38079..3bd7a0e998a 100644 --- a/tests/cases/compiler/asyncFunctionReturnType.ts +++ b/tests/cases/compiler/asyncFunctionReturnType.ts @@ -8,3 +8,69 @@ async function fAsyncExplicit(): Promise<[number, boolean]> { // This is contextually typed as a tuple. return [1, true]; } + +// https://github.com/Microsoft/TypeScript/issues/13128 +interface Obj { + stringProp: string; + anyProp: any; +} + +async function fIndexedTypeForStringProp(obj: Obj): Promise { + return obj.stringProp; +} + +async function fIndexedTypeForPromiseOfStringProp(obj: Obj): Promise { + return Promise.resolve(obj.stringProp); +} + +async function fIndexedTypeForExplicitPromiseOfStringProp(obj: Obj): Promise { + return Promise.resolve(obj.stringProp); +} + +async function fIndexedTypeForAnyProp(obj: Obj): Promise { + return obj.anyProp; +} + +async function fIndexedTypeForPromiseOfAnyProp(obj: Obj): Promise { + return Promise.resolve(obj.anyProp); +} + +async function fIndexedTypeForExplicitPromiseOfAnyProp(obj: Obj): Promise { + return Promise.resolve(obj.anyProp); +} + +async function fGenericIndexedTypeForStringProp(obj: TObj): Promise { + return obj.stringProp; +} + +async function fGenericIndexedTypeForPromiseOfStringProp(obj: TObj): Promise { + return Promise.resolve(obj.stringProp); +} + +async function fGenericIndexedTypeForExplicitPromiseOfStringProp(obj: TObj): Promise { + return Promise.resolve(obj.stringProp); +} + +async function fGenericIndexedTypeForAnyProp(obj: TObj): Promise { + return obj.anyProp; +} + +async function fGenericIndexedTypeForPromiseOfAnyProp(obj: TObj): Promise { + return Promise.resolve(obj.anyProp); +} + +async function fGenericIndexedTypeForExplicitPromiseOfAnyProp(obj: TObj): Promise { + return Promise.resolve(obj.anyProp); +} + +async function fGenericIndexedTypeForKProp(obj: TObj, key: K): Promise { + return obj[key]; +} + +async function fGenericIndexedTypeForPromiseOfKProp(obj: TObj, key: K): Promise { + return Promise.resolve(obj[key]); +} + +async function fGenericIndexedTypeForExplicitPromiseOfKProp(obj: TObj, key: K): Promise { + return Promise.resolve(obj[key]); +} \ No newline at end of file