Skip to content

Commit 6a93ed9

Browse files
committed
Create returnOnlySignature only when inferences will possibly be made
1 parent 8b83703 commit 6a93ed9

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26051,15 +26051,19 @@ namespace ts {
2605126051
if (checkMode && checkMode & CheckMode.SkipContextSensitive && isContextSensitive(node)) {
2605226052
// Skip parameters, return signature with return type that retains noncontextual parts so inferences can still be drawn in an early stage
2605326053
if (!getEffectiveReturnTypeNode(node) && hasContextSensitiveReturnExpression(node)) {
26054-
const links = getNodeLinks(node);
26055-
if (links.contextFreeType) {
26056-
return links.contextFreeType;
26057-
}
26058-
const returnType = getReturnTypeFromBody(node, checkMode);
26059-
const returnOnlySignature = createSignature(undefined, undefined, undefined, emptyArray, returnType, /*resolvedTypePredicate*/ undefined, 0, SignatureFlags.None);
26060-
const returnOnlyType = createAnonymousType(node.symbol, emptySymbols, [returnOnlySignature], emptyArray, undefined, undefined);
26061-
returnOnlyType.objectFlags |= ObjectFlags.NonInferrableType;
26062-
return links.contextFreeType = returnOnlyType;
26054+
// Return plain anyFunctionType if there is no possibility we'll make inferences from the return type
26055+
const contextualSignature = getContextualSignature(node);
26056+
if (contextualSignature && couldContainTypeVariables(getReturnTypeOfSignature(contextualSignature))) {
26057+
const links = getNodeLinks(node);
26058+
if (links.contextFreeType) {
26059+
return links.contextFreeType;
26060+
}
26061+
const returnType = getReturnTypeFromBody(node, checkMode);
26062+
const returnOnlySignature = createSignature(undefined, undefined, undefined, emptyArray, returnType, /*resolvedTypePredicate*/ undefined, 0, SignatureFlags.None);
26063+
const returnOnlyType = createAnonymousType(node.symbol, emptySymbols, [returnOnlySignature], emptyArray, undefined, undefined);
26064+
returnOnlyType.objectFlags |= ObjectFlags.NonInferrableType;
26065+
return links.contextFreeType = returnOnlyType;
26066+
}
2606326067
}
2606426068
return anyFunctionType;
2606526069
}

0 commit comments

Comments
 (0)