mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-31 18:10:56 -05:00
Make function properties context-sensitive based on their return statements (#50903)
This commit is contained in:
committed by
GitHub
parent
4fcb8b8be6
commit
acfb0b53d1
@@ -19114,8 +19114,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
|
||||
function hasContextSensitiveReturnExpression(node: FunctionLikeDeclaration) {
|
||||
// TODO(anhans): A block should be context-sensitive if it has a context-sensitive return value.
|
||||
return !node.typeParameters && !getEffectiveReturnTypeNode(node) && !!node.body && node.body.kind !== SyntaxKind.Block && isContextSensitive(node.body);
|
||||
if (node.typeParameters || getEffectiveReturnTypeNode(node) || !node.body) {
|
||||
return false;
|
||||
}
|
||||
if (node.body.kind !== SyntaxKind.Block) {
|
||||
return isContextSensitive(node.body);
|
||||
}
|
||||
return !!forEachReturnStatement(node.body as Block, (statement) => !!statement.expression && isContextSensitive(statement.expression));
|
||||
}
|
||||
|
||||
function isContextSensitiveFunctionOrObjectLiteralMethod(func: Node): func is FunctionExpression | ArrowFunction | MethodDeclaration {
|
||||
|
||||
Reference in New Issue
Block a user