Fixed element access expression writes for divergent write types (#55585)

This commit is contained in:
Mateusz Burzyński
2023-09-14 01:14:07 +02:00
committed by GitHub
parent c0b39c6967
commit e6321d77c7
15 changed files with 1182 additions and 12 deletions

View File

@@ -686,6 +686,7 @@ import {
isRequireCall,
isRestParameter,
isRestTypeNode,
isRightSideOfAccessExpression,
isRightSideOfQualifiedNameOrPropertyAccess,
isRightSideOfQualifiedNameOrPropertyAccessOrJSDocMemberName,
isSameEntityName,
@@ -17737,7 +17738,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return autoType;
}
}
const propType = getTypeOfSymbol(prop);
const propType = accessFlags & AccessFlags.Writing ? getWriteTypeOfSymbol(prop) : getTypeOfSymbol(prop);
return accessExpression && getAssignmentTargetKind(accessExpression) !== AssignmentKind.Definite ? getFlowTypeOfReference(accessExpression, propType) :
accessNode && isIndexedAccessTypeNode(accessNode) && containsMissingType(propType) ? getUnionType([propType, undefinedType]) :
propType;
@@ -28229,7 +28230,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// to it at the given location. Since we have no control flow information for the
// hypothetical reference (control flow information is created and attached by the
// binder), we simply return the declared type of the symbol.
return getNonMissingTypeOfSymbol(symbol);
return isRightSideOfAccessExpression(location) && isWriteAccess(location.parent) ? getWriteTypeOfSymbol(symbol) : getNonMissingTypeOfSymbol(symbol);
}
function getControlFlowContainer(node: Node): Node {

View File

@@ -7259,8 +7259,8 @@ export function isRightSideOfQualifiedNameOrPropertyAccess(node: Node) {
/** @internal */
export function isRightSideOfAccessExpression(node: Node) {
return isPropertyAccessExpression(node.parent) && node.parent.name === node
|| isElementAccessExpression(node.parent) && node.parent.argumentExpression === node;
return !!node.parent && (isPropertyAccessExpression(node.parent) && node.parent.name === node
|| isElementAccessExpression(node.parent) && node.parent.argumentExpression === node);
}
/** @internal */