英文:
An if statement using an object hierachy in Typescript
问题
我尝试使用以下层次结构构建逻辑语句:
if ((config.elementConfig.curve[0].dataset[0].splitBy = '我的离散变量')) {.....
我收到了来自TypeScript的错误消息:"错误 未预期的常量条件 no-constant-condition"。
我应该如何更改它,以使TypeScript接受它?
英文:
I am trying to base a logical statement using a hierachy like below
if ((config.elementConfig.curve[0].dataset[0].splitBy = 'my descrete var')) {.....
I get the error "error Unexpected constant condition no-constant-condition"
from typescript
how do I change it so typescript will like it
答案1
得分: 0
I suspect your issue is that you are trying to do a variable assignment, not an evaluation. You want to use ==
, not =
.
=
is used to assign:
const myValue = "thing";
==
is used to evaluate.
It's complaining that the expression you're giving it doesn't evaluate to something the if condition can check!
if (myValue === "thing") {
So you probably intend to have:
if ((config.elementConfig.curve[0].dataset[0].splitBy == 'my descrete var')
英文:
I suspect your issue is that you are trying to do a variable asignment, not an evaluation. You want to use ==
, not =
.
=
is used to assign:
const myValue = "thing";
==
is used to evaluate.
It's complaining that the expression you're giving it doesn't evaluate to something the if condition can check!
if (myValue === "thing") {
So you probably intend to have:
if ((config.elementConfig.curve[0].dataset[0].splitBy == 'my descrete var')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论