Back to Biomejs

noTsIgnore

src/content/docs/linter/rules/no-ts-ignore.mdx

latest6.4 KB
Original Source

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v2.0.0` - Diagnostic Category: [`lint/suspicious/noTsIgnore`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Inspired from [`@typescript-eslint/ban-ts-comment`](https://typescript-eslint.io/rules/ban-ts-comment)

How to configure

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

Description

Prevents the use of the TypeScript directive @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.

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
// @ts-ignore
let foo;
<pre class="language-text"><code class="language-text">code-block.ts:1:4 <a href="https://biomejs.dev/linter/rules/no-ts-ignore">lint/suspicious/noTsIgnore</a> <span style="color: #000; background-color: #ddd;"> FIXABLE </span> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Unsafe use of the </span><span style="color: Orange;"><strong>@ts-ignore</strong></span><span style="color: Orange;"> directive found in this comment.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>// @ts-ignore <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong>let foo; <strong>3 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">The directive is applied to this line.</span> <strong>1 │ </strong>// @ts-ignore <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong>let foo; <strong> │ </strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>3 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">The </span><span style="color: lightgreen;"><strong>@ts-ignore</strong></span><span style="color: lightgreen;"> directive suppresses any kind of error, even possible errors that might be fixed by upstream libraries or the compiler itself.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Safe fix</span><span style="color: lightgreen;">: </span><span style="color: lightgreen;">Use the </span><span style="color: lightgreen;"><strong>@ts-expect-error</strong></span><span style="color: lightgreen;"> directive instead.</span> <strong>1</strong> <strong> │ </strong><span style="color: Tomato;">-</span> <span style="color: Tomato;">/</span><span style="color: Tomato;">/</span><span style="color: Tomato;"><span style="opacity: 0.8;">·</span></span><span style="color: Tomato;">@</span><span style="color: Tomato;">t</span><span style="color: Tomato;">s</span><span style="color: Tomato;">-</span><span style="color: Tomato;"><strong>i</strong></span><span style="color: Tomato;"><strong>g</strong></span><span style="color: Tomato;"><strong>n</strong></span><span style="color: Tomato;"><strong>o</strong></span><span style="color: Tomato;"><strong>r</strong></span><span style="color: Tomato;"><strong>e</strong></span> <strong>1</strong><strong> │ </strong><span style="color: MediumSeaGreen;">+</span> <span style="color: MediumSeaGreen;">/</span><span style="color: MediumSeaGreen;">/</span><span style="color: MediumSeaGreen;"><span style="opacity: 0.8;">·</span></span><span style="color: MediumSeaGreen;">@</span><span style="color: MediumSeaGreen;">t</span><span style="color: MediumSeaGreen;">s</span><span style="color: MediumSeaGreen;">-</span><span style="color: MediumSeaGreen;"><strong>e</strong></span><span style="color: MediumSeaGreen;"><strong>x</strong></span><span style="color: MediumSeaGreen;"><strong>p</strong></span><span style="color: MediumSeaGreen;"><strong>e</strong></span><span style="color: MediumSeaGreen;"><strong>c</strong></span><span style="color: MediumSeaGreen;"><strong>t</strong></span><span style="color: MediumSeaGreen;"><strong>-</strong></span><span style="color: MediumSeaGreen;"><strong>e</strong></span><span style="color: MediumSeaGreen;"><strong>r</strong></span><span style="color: MediumSeaGreen;"><strong>r</strong></span><span style="color: MediumSeaGreen;"><strong>o</strong></span><span style="color: MediumSeaGreen;"><strong>r</strong></span> <strong>2</strong> <strong>2</strong><strong> │ </strong> let foo; <strong>3</strong> <strong>3</strong><strong> │ </strong> </code></pre>

Valid

ts
// @ts-expect-error
let foo;
</TabItem> </Tabs>