Merge pull request #17771 from Microsoft/fixCircularContextualType

Fix circular contextual return type error
This commit is contained in:
Anders Hejlsberg
2017-08-16 09:17:15 +02:00
committed by GitHub
5 changed files with 74 additions and 1 deletions

View File

@@ -6582,6 +6582,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));
@@ -12955,7 +12959,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(<FunctionExpression>functionDecl);
if (signature) {
if (signature && !isResolvingReturnTypeOfSignature(signature)) {
return getReturnTypeOfSignature(signature);
}