【发布时间】:2018-06-25 12:01:51
【问题描述】:
这实际上是在阻止我的 Angular 应用程序运行。这是一个派生示例,我设置的const 只是为了测试函数中的一些值,所以有一些方法可以解决这个问题,但我想知道发生了什么似乎很奇怪。
以下代码给出了 tslint 错误 Type '"Red"' is not comparable to type '"Green"'. Happens with if statements as well.
const color = 'Red'
switch(color) {
case 'Red':
//do something
case 'Green':
//something else
}
为什么它使用字符串作为类型?为什么我不能将 const 字符串变量与字符串进行比较?这似乎是一个错误。
【问题讨论】:
-
const color: string = 'Red'?
标签: string typescript constants tslint