如何忽略打字错误与@t- 忽略?

我有一个案例,我导入了一个纯粹的 JavaScript 库在 TypeScript 项目给我的唠叨 Could not find a declaration file for module xxx消息。所以在阅读后,我发现我可以抑制与 @ts-ignore的评论。然而,在冒犯行之前添加这个注释,我得到了另一个错误

不要使用“//@ts-annon”注释,因为它们会禁止编译错误@typeescript-eslint/ban-ts-annon

如何修复此错误并禁止显示原始邮件?

86847 次浏览

You can stop using @ts-ignore

Or you can disable the eslint rule. Add that in your eslint config (.eslintrc or equivalent)

...
"rules": {
"@typescript-eslint/ban-ts-ignore": "off"
}
...

EDIT: If you are using @typescript-eslint/eslint-plugin version 2.18 or higher, the rule is called ban-ts-comment and you need to add

"@typescript-eslint/ban-ts-comment": "off"

instead. Here is the changelog

Posting as an answer instead of comment to the accepted answer because of my lack of reputation. I still want to contribute and possibly help someone out.

The rule for me was

@typescript-eslint/ban-ts-comment

not ban-ts-ignore

If running the application using npm then the rules can be specified in package.json. The syntax is rather different from the other answers:

 "eslintConfig": {
. . .
"rules": {
"ban-ts-comment": 0
},
. . .
}

And I confirm using ban-ts-commentinstead of ban-ts-ignore (tested only with typescript-eslint/eslint-plugin v2.33.0)

All answers here suggest disabling the whole eslint rule which is not very practical, a better solution will be to ignore the eslint error at that specific location like this:

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

I recommend allowing @ts-ignore with an enforced description. This can be achieved by the following config in .eslintrc.js. Link to documentation

rules: {
'@typescript-eslint/ban-ts-comment': [
'error',
{'ts-ignore': 'allow-with-description'},
],
},