1

While writing my angular application, I got this "strange" error message:

"Must be lvalue" Error

The code runs perfectly fine and I couldn't find any documentation for this error message. What does it mean?

The code is from : https://stackoverflow.com/a/45144391/639035 which is an accepted answer with 15 up votes.

Code:

<input placeholder="TEST"
       [ngModel]="phone_numbers && phone_numbers[0]?.full_number"
       (ngModelChange)="phone_numbers?.length && phone_numbers[0].full_number=$event">

Error Message:

Must be lvalue

Must be lvalue

Stefan
  • 14,826
  • 17
  • 80
  • 143

1 Answers1

3

This is how webstorm inspection by using JSAnnotator works.

Try creating simple js file with the following code:

let a,b;
a && b=1;

enter image description here

It would be better if that error would sound like:

ReferenceError: invalid assignment left-hand side

See also issue

Webstorm warns us that this code is unusual case and we can be wrong with writting it, for example

if (a === 1 && b = 2) {
                 /\
   Seems it should be == or ===. 
   So it's easy to make such mistake like this

How can we suppress this error?

  • rewrite code in the following way

(ngModelChange)="phone_numbers?.length ? phone_numbers[0]['full_number']=$event : null"
  • supress JSAnnotator for the input element

<!--suppress JSAnnotator -->
<input placeholder="TEST"
       [ngModel]="phone_numbers && phone_numbers[0]?.full_number"
       (ngModelChange)="phone_numbers?.length && phone_numbers[0]['full_number']=$event">
   

Again, it's just a warning and it's up to you how to deal with it.

Community
  • 1
  • 1
yurzui
  • 205,937
  • 32
  • 433
  • 399
  • I guess version 2019.1 is not release, which will fix it. Great answer – Stefan Feb 12 '19 at 12:55
  • In 2019.1, it shows `Invalid left-hand side in assignment expression` warning for code like yours. You can try the [EAP](https://www.jetbrains.com/webstorm/eap/) build – lena Feb 12 '19 at 13:59