mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-18 07:29:16 -05:00
Fixed element access expression writes for divergent write types (#55585)
This commit is contained in:
committed by
GitHub
parent
c0b39c6967
commit
e6321d77c7
@@ -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 {
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user