Angular 2 : "Expected the operants to be of similar type or any" linting error

标签 angular typescript eslint

我有一个共享服务文件,它定义了一个像这样的变量:

export class SharedService {
    activeModal: String;
}

然后我有一个导入服务并定义它的组件文件:

constructor(public sharedService: SharedService) {
}

在该组件的模板文件中,我检查模态的值:

<div *ngIf="sharedService.activeModal === 'login'"></div>

一切正常,但在编辑器中,sharedService.activeModal === 'login' 部分下方有一条红色波浪线,将鼠标悬停在它上面会显示此 linting 错误:

[Angular] Expected the operants to be of similar type or any
property sharedService of ModalComponent

知道我做错了什么吗?

最佳答案

activeModal 的声明中尝试使用小写的 string(原语,而不是包装对象类型 String)。

关于 Angular 2 : "Expected the operants to be of similar type or any" linting error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51736051/

相关文章:

angular - @ViewChild 中的读取参数是什么

typescript - 一个类只能实现一个对象类型或对象类型与静态已知成员的交集

babeljs - eslint/babel-eslint 与 escope 的问题

Angular (4) : Custom Error Handler & DI: Cannot instantiate cyclic dependency

node.js - npm install 正在我的 Angular 项目根目录中构建 .cmd 文件

javascript - Perfect-scrollbar onload 滚动到底部并使用无限滚动

interface - typescript 函数接口(interface)

javascript - 在 Cypress 中保存变量

angular - 升级到 EsLint : Error with angular. json(原理图:convert-tslint-to-eslint)

javascript - ESlint 初始化设置未显示 VSCode Windows 操作系统