Webstorm:什么是“必须是左值"?意思 [英] Webstorm: What does "Must be lvalue" mean

查看:29
本文介绍了Webstorm:什么是“必须是左值"?意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写我的 Angular 应用程序时,我收到了这个奇怪"的错误消息:

代码运行得非常好,我找不到有关此错误消息的任何文档.什么意思?

代码来自:

如果该错误听起来像:

<块引用>

ReferenceError: 左侧无效赋值

另见问题

Webstorm 警告我们这个代码是不寻常的情况,我们可能会写错,例如

if (a === 1 && b = 2) {/\似乎应该是 == 或 ===.所以很容易犯这样的错误

我们怎样才能抑制这个错误?

  • 按照以下方式重写代码

(ngModelChange)=phone_numbers?.length ?phone_numbers[0]['full_number']=$event : null"

  • 抑制 input 元素的 JSAnnotator

<输入占位符=测试"[ngModel]="phone_numbers &&phone_numbers[0]?.full_number"(ngModelChange)="phone_numbers?.length &&phone_numbers[0]['full_number']=$event">

再说一次,这只是一个警告,如何处理取决于您.

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

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

解决方案

This is how webstorm inspection by using JSAnnotator works.

Try creating simple js file with the following code:

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

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.

这篇关于Webstorm:什么是“必须是左值"?意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆