# @typescript-eslint/ban-ts-comment

> Disallow `@ts-ignore` and `@ts-nocheck`, and require a reason after `@ts-expect-error`

A `@ts-` comment turns off type errors. `@ts-ignore` hides every error on the next line, now and later, and stays there when the error is gone. `@ts-nocheck` turns off type checking for the whole file.

`@ts-expect-error` is the safer one, because TypeScript complains when the line no longer has an error. By default it's allowed if a description of at least 3 characters follows it, so the next reader knows why it's there.

This rule is on by default in TypeScript files.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

On by default as a warning. To turn it off:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/ban-ts-comment" = "off" # or "error"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/ban-ts-comment" = ["warn", {
  # true, false, "allow-with-description" or object
  ts-expect-error = "allow-with-description",
  ts-ignore = true, # true, false, "allow-with-description" or object
  ts-nocheck = true, # true, false, "allow-with-description" or object
  ts-check = false, # true, false, "allow-with-description" or object
  minimumDescriptionLength = 3,
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```ts
// @ts-ignore
const port: number = process.env.PORT;
```

{/* bad */}
```ts
// @ts-expect-error
const port: number = process.env.PORT;
```

{/* bad */}
```ts
// @ts-nocheck
export const port: number = process.env.PORT;
```

Not reported:

{/* good */}
```ts
// @ts-expect-error: PORT is always set in production
const port: number = process.env.PORT;
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `ts-expect-error` | `"allow-with-description"` | How to treat `@ts-expect-error`. |
| `ts-ignore` | `true` | How to treat `@ts-ignore`. |
| `ts-nocheck` | `true` | How to treat `@ts-nocheck`. |
| `ts-check` | `false` | How to treat `@ts-check`. |
| `minimumDescriptionLength` | `3` | How many characters a description needs. |

Each directive takes one of these values:

| Value | What it does |
| --- | --- |
| `true` | Report the directive. |
| `false` | Allow it. |
| `"allow-with-description"` | Allow it if a description follows. |
| `{ "descriptionFormat": "..." }` | Allow it if the description matches this regular expression. |

{/* good {"options": [{"ts-ignore": "allow-with-description"}]} */}
```ts
// @ts-ignore: the types of this package are wrong
import legacy from "legacy-package";
```

{/* bad {"options": [{"minimumDescriptionLength": 10}]} */}
```ts
// @ts-expect-error: todo
const port: number = process.env.PORT;
```

The regular expression is tested on everything after the directive, including the space or colon:

{/* good {"options": [{"ts-expect-error": {"descriptionFormat": "^: TS\\d+ because .+$"}}]} */}
```ts
// @ts-expect-error: TS2322 because PORT is always set
const port: number = process.env.PORT;
```

{/* bad {"options": [{"ts-expect-error": {"descriptionFormat": "^: TS\\d+ because .+$"}}]} */}
```ts
// @ts-expect-error: PORT is always set
const port: number = process.env.PORT;
```
