@@ -26051,15 +26051,19 @@ namespace ts {
26051
26051
if (checkMode && checkMode & CheckMode.SkipContextSensitive && isContextSensitive(node)) {
26052
26052
// Skip parameters, return signature with return type that retains noncontextual parts so inferences can still be drawn in an early stage
26053
26053
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
+ }
26063
26067
}
26064
26068
return anyFunctionType;
26065
26069
}
0 commit comments