Skip to content

noTsIgnore

¥Summary

¥How to configure

biome.json
{
"linter": {
"rules": {
"suspicious": {
"noTsIgnore": "error"
}
}
}
}

¥Description

防止使用 TypeScript 指令 @ts-ignore

¥Prevents the use of the TypeScript directive @ts-ignore.

指令 @ts-ignore 会抑制所有编译错误,即使是来自上游库或编译器本身的 bug 也不例外。如果你使用 @ts-ignore,则无法得知该错误何时以及是否已修复。

¥The directive @ts-ignore suppresses all compilation errors, even ones that could be considered bugs coming from an upstream library or the compiler itself. If you use @ts-ignore, it won’t be possible to know when and if the bug is fixed.

该规则提倡使用 @ts-expect-error 指令,该指令旨在在没有错误的情况下引发错误。这意味着一旦错误修复,你可以安全地删除该指令。

¥The rule promotes the use the directive @ts-expect-error, which is meant to raise an error if there aren’t any errors. This means that once the bug is fixed, you can delete the directive, safely.

¥Examples

¥Invalid

// @ts-ignore
let foo;
code-block.ts:1:4 lint/suspicious/noTsIgnore  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unsafe use of the @ts-ignore directive found in this comment.

> 1 │ // @ts-ignore
^^^^^^^^^^
2 │ let foo;
3 │

The directive is applied to this line.

1 │ // @ts-ignore
> 2 │ let foo;
^^^
3 │

The @ts-ignore directive suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself.

Safe fix: Use the @ts-expect-error directive instead.

1 - //·@ts-ignore
1+ //·@ts-expect-error
2 2 let foo;
3 3

¥Valid

// @ts-expect-error
let foo;

¥Related links