mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
Create returnOnlySignature only when inferences will possibly be made (#35173)
* Create returnOnlySignature only when inferences will possibly be made * Add regression test * Accept new baselines
This commit is contained in:
@@ -26129,15 +26129,19 @@ namespace ts {
|
||||
if (checkMode && checkMode & CheckMode.SkipContextSensitive && isContextSensitive(node)) {
|
||||
// Skip parameters, return signature with return type that retains noncontextual parts so inferences can still be drawn in an early stage
|
||||
if (!getEffectiveReturnTypeNode(node) && hasContextSensitiveReturnExpression(node)) {
|
||||
const links = getNodeLinks(node);
|
||||
if (links.contextFreeType) {
|
||||
return links.contextFreeType;
|
||||
// Return plain anyFunctionType if there is no possibility we'll make inferences from the return type
|
||||
const contextualSignature = getContextualSignature(node);
|
||||
if (contextualSignature && couldContainTypeVariables(getReturnTypeOfSignature(contextualSignature))) {
|
||||
const links = getNodeLinks(node);
|
||||
if (links.contextFreeType) {
|
||||
return links.contextFreeType;
|
||||
}
|
||||
const returnType = getReturnTypeFromBody(node, checkMode);
|
||||
const returnOnlySignature = createSignature(undefined, undefined, undefined, emptyArray, returnType, /*resolvedTypePredicate*/ undefined, 0, SignatureFlags.None);
|
||||
const returnOnlyType = createAnonymousType(node.symbol, emptySymbols, [returnOnlySignature], emptyArray, undefined, undefined);
|
||||
returnOnlyType.objectFlags |= ObjectFlags.NonInferrableType;
|
||||
return links.contextFreeType = returnOnlyType;
|
||||
}
|
||||
const returnType = getReturnTypeFromBody(node, checkMode);
|
||||
const returnOnlySignature = createSignature(undefined, undefined, undefined, emptyArray, returnType, /*resolvedTypePredicate*/ undefined, 0, SignatureFlags.None);
|
||||
const returnOnlyType = createAnonymousType(node.symbol, emptySymbols, [returnOnlySignature], emptyArray, undefined, undefined);
|
||||
returnOnlyType.objectFlags |= ObjectFlags.NonInferrableType;
|
||||
return links.contextFreeType = returnOnlyType;
|
||||
}
|
||||
return anyFunctionType;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user