Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Linter · Rules

@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.

Configure

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

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

Every option, set to its default:

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,
}]

Examples

Reported:

// @ts-ignore
const port: number = process.env.PORT;
// @ts-expect-error
const port: number = process.env.PORT;
// @ts-nocheck
export const port: number = process.env.PORT;

Not reported:

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

Options

OptionDefaultWhat it does
ts-expect-error"allow-with-description"How to treat @ts-expect-error.
ts-ignoretrueHow to treat @ts-ignore.
ts-nochecktrueHow to treat @ts-nocheck.
ts-checkfalseHow to treat @ts-check.
minimumDescriptionLength3How many characters a description needs.

Each directive takes one of these values:

ValueWhat it does
trueReport the directive.
falseAllow it.
"allow-with-description"Allow it if a description follows.
{ "descriptionFormat": "..." }Allow it if the description matches this regular expression.
// @ts-ignore: the types of this package are wrong
import legacy from "legacy-package";
// @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:

// @ts-expect-error: TS2322 because PORT is always set
const port: number = process.env.PORT;
// @ts-expect-error: PORT is always set
const port: number = process.env.PORT;