mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-15 22:15:05 -05:00
Still generate signatures in SkipContextSensitive mode just to match on return types (#25937)
* Still generate signatures in SkipContextSensitive mode just to match on return types * Add cache for context-free type of a signature node * Accept post-merge baseline
This commit is contained in:
@@ -10369,7 +10369,10 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return hasContextSensitiveReturnExpression(node);
|
||||
}
|
||||
|
||||
function hasContextSensitiveReturnExpression(node: FunctionLikeDeclaration) {
|
||||
// TODO(anhans): A block should be context-sensitive if it has a context-sensitive return value.
|
||||
const body = node.body!;
|
||||
return body.kind === SyntaxKind.Block ? false : isContextSensitive(body);
|
||||
@@ -20704,6 +20707,16 @@ namespace ts {
|
||||
|
||||
// The identityMapper object is used to indicate that function expressions are wildcards
|
||||
if (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;
|
||||
}
|
||||
const returnType = getReturnTypeFromBody(node, checkMode);
|
||||
const singleReturnSignature = createSignature(undefined, undefined, undefined, emptyArray, returnType, /*resolvedTypePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
|
||||
return links.contextFreeType = createAnonymousType(node.symbol, emptySymbols, [singleReturnSignature], emptyArray, undefined, undefined);
|
||||
}
|
||||
return anyFunctionType;
|
||||
}
|
||||
|
||||
|
||||
@@ -3667,6 +3667,7 @@ namespace ts {
|
||||
superCall?: SuperCall; // Cached first super-call found in the constructor. Used in checking whether super is called before this-accessing
|
||||
switchTypes?: Type[]; // Cached array of switch case expression types
|
||||
jsxNamespace?: Symbol | false; // Resolved jsx namespace symbol for this node
|
||||
contextFreeType?: Type; // Cached context-free type used by the first pass of inference; used when a function's return is partially contextually sensitive
|
||||
}
|
||||
|
||||
export const enum TypeFlags {
|
||||
|
||||
Reference in New Issue
Block a user