From dacc851434af9bbf2388a6db1438acabc2d886ef Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 14 Aug 2017 09:01:50 +0200 Subject: [PATCH] No contextual return type when type is circular --- src/compiler/checker.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 07c94bd746..1ba33f8c82 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6576,6 +6576,10 @@ namespace ts { return signature.resolvedReturnType; } + function isResolvingReturnTypeOfSignature(signature: Signature) { + return !signature.resolvedReturnType && findResolutionCycleStartIndex(signature, TypeSystemPropertyName.ResolvedReturnType) >= 0; + } + function getRestTypeOfSignature(signature: Signature): Type { if (signature.hasRestParameter) { const type = getTypeOfSymbol(lastOrUndefined(signature.parameters)); @@ -12949,7 +12953,7 @@ namespace ts { // Otherwise, if the containing function is contextually typed by a function type with exactly one call signature // and that call signature is non-generic, return statements are contextually typed by the return type of the signature const signature = getContextualSignatureForFunctionLikeDeclaration(functionDecl); - if (signature) { + if (signature && !isResolvingReturnTypeOfSignature(signature)) { return getReturnTypeOfSignature(signature); }