Make function properties context-sensitive based on their return statements (#50903)

This commit is contained in:
Mateusz Burzyński
2023-03-20 21:53:16 +01:00
committed by GitHub
parent 4fcb8b8be6
commit acfb0b53d1
4 changed files with 90 additions and 2 deletions

View File

@@ -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 {