在某些情况下,我正在TypeScript项目中导入一个纯粹的JavaScript库,这给了我{的Could not find a declaration file for module xxx
消息。因此,在阅读之后,我发现可以用@ts-ignore
进行注释来禁止它。但是在有问题的行之前添加该评论,我又遇到了另一个错误
请勿使用“ // @ ts-ignore”注释,因为它们会抑制编译错误@ typescript-eslint / ban-ts-ignore
如何解决此错误并隐藏原始消息?
答案 0 :(得分:38)
您可以停止使用@ts-ignore
:troll:
或者您可以禁用eslint规则。将其添加到您的eslint配置(.eslintrc
或同等版本)中
...
"rules": {
"@typescript-eslint/ban-ts-ignore": "off"
}
...
编辑:如果您使用的是@typescript-eslint/eslint-plugin
版本2.18或更高版本,则该规则称为ban-ts-comment
,您需要添加
"@typescript-eslint/ban-ts-comment": "off"
相反。这是changelog
答案 1 :(得分:21)
由于我缺乏声誉,因此将其发布为答案而不是评论已接受的答案。我仍然想做出贡献,并可能帮助某人。
对我来说,规则是
@typescript-eslint/ban-ts-comment
不是ban-ts-ignore
答案 2 :(得分:16)
这里的所有答案都建议禁用整个 eslint 规则,这不是很实用,更好的解决方案是忽略该特定位置的 eslint 错误,如下所示:
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore