MCPcopy Create free account
hub / github.com/microsoft/typescript-go / checkAssignmentOperator

Method checkAssignmentOperator

internal/checker/checker.go:12719–12743  ·  view source on GitHub ↗
(left *ast.Node, operator ast.Kind, right *ast.Node, leftType *Type, rightType *Type)

Source from the content-addressed store, hash-verified

12717}
12718
12719func (c *Checker) checkAssignmentOperator(left *ast.Node, operator ast.Kind, right *ast.Node, leftType *Type, rightType *Type) {
12720 if ast.IsAssignmentOperator(operator) {
12721 // We ignore assignments of undefined to CommonJS exports when there are multiple assignment declarations
12722 if ast.IsDeclarationNode(left.Parent) && ast.GetAssignmentDeclarationKind(left.Parent) == ast.JSDeclarationKindExportsProperty {
12723 if symbol := c.symbolNodeLinks.Get(left).resolvedSymbol; symbol != nil && len(symbol.Declarations) > 1 && rightType.flags&TypeFlagsUndefined != 0 {
12724 return
12725 }
12726 }
12727 // getters can be a subtype of setters, so to check for assignability we use the setter's type instead
12728 if ast.IsCompoundAssignment(operator) && ast.IsPropertyAccessExpression(left) {
12729 leftType = c.checkPropertyAccessExpression(left, CheckModeNormal, true /*writeOnly*/)
12730 }
12731 if c.checkReferenceExpression(left, diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access, diagnostics.The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access) {
12732 var headMessage *diagnostics.Message
12733 if c.exactOptionalPropertyTypes && ast.IsPropertyAccessExpression(left) && c.maybeTypeOfKind(rightType, TypeFlagsUndefined) {
12734 target := c.getTypeOfPropertyOfType(c.getTypeOfExpression(left.Expression()), left.Name().Text())
12735 if c.isExactOptionalPropertyMismatch(rightType, target) {
12736 headMessage = diagnostics.Type_0_is_not_assignable_to_type_1_with_exactOptionalPropertyTypes_Colon_true_Consider_adding_undefined_to_the_type_of_the_target
12737 }
12738 }
12739 // to avoid cascading errors check assignability only if 'isReference' check succeeded and no errors were reported
12740 c.checkTypeAssignableToAndOptionallyElaborate(rightType, leftType, left, right, headMessage, nil)
12741 }
12742 }
12743}
12744
12745func (c *Checker) bothAreBigIntLike(left *Type, right *Type) bool {
12746 return c.isTypeAssignableToKind(left, TypeFlagsBigIntLike) && c.isTypeAssignableToKind(right, TypeFlagsBigIntLike)

Callers 1

Tested by

no test coverage detected