Skip to content

tsComments

Reports problematic TypeScript comment directives or requires descriptions after directives.

✅ This rule is included in the ts logical presets.

TypeScript provides several comment directives that can be used to alter how it processes files. Using these to suppress TypeScript compiler errors reduces the effectiveness of TypeScript overall. Instead, it’s generally better to correct the types of code, to make directives unnecessary.

This rule can report on uses of the following comment directives:

  • @ts-expect-error
  • @ts-ignore
  • @ts-nocheck

By default, all directives are allowed. Use the options to ban specific directives or require descriptions.

@ts-ignore permanently suppresses errors even after they’re fixed. @ts-expect-error will report if the next line has no error, helping identify stale suppressions.

// @ts-ignore
const
const value: string
value
: string = 123;

@ts-nocheck disables type checking for the entire file. Prefer fixing errors or using targeted suppressions.

// @ts-nocheck
const
const value: any
value
=
any
unknownFunction
();

Each directive option can be configured with one of the following values:

  • true — Ban the directive entirely
  • false — Allow the directive (default)
  • "allow-with-description" — Allow only if a description is provided
  • { descriptionFormat: "regex" } — Allow only if the description matches the regex

Configuration for @ts-expect-error directives. Default: false (allowed).

// With { allowTsExpectError: "allow-with-description" }
// ❌ Invalid - no description
// @ts-expect-error
const
const value: string
value
: string = 123;
// ✅ Valid - has description
// @ts-expect-error: testing number assignment
const
const value: string
value
: string = 123;

Configuration for @ts-ignore directives. Default: false (allowed).

When banned with true, this rule provides a fixer that replaces @ts-ignore with @ts-expect-error.

// With { allowTsIgnore: true }
// ❌ Invalid - ts-ignore is banned, will suggest @ts-expect-error
// @ts-ignore
const
const value: string
value
: string = 123;
// With { allowTsIgnore: "allow-with-description" }
// ❌ Invalid - no description
// @ts-ignore
const
const value: string
value
: string = 123;
// ✅ Valid - has description
// @ts-ignore: legacy code that will be fixed in ISSUE-123
const
const value: string
value
: string = 123;

Configuration for @ts-nocheck directives. Default: false (allowed).

// With { allowTsNocheck: true }
// ❌ Invalid - ts-nocheck is banned
// @ts-nocheck
const
const value: any
value
=
any
unknownFunction
();

The minimum length required for a description when using "allow-with-description". Default: 10.

// With { allowTsExpectError: "allow-with-description", minimumDescriptionLength: 15 }
// ❌ Invalid - description too short
// @ts-expect-error: test
const
const value: string
value
: string = 123;
// ✅ Valid - description is long enough
// @ts-expect-error: testing number to string assignment
const
const value: string
value
: string = 123;

When using an object configuration, you can specify a descriptionFormat regex that the description must match:

// With { allowTsExpectError: { descriptionFormat: "^: TS\\d+ because .+$" } }
// ❌ Invalid - description doesn't match format
// @ts-expect-error: some random reason
const
const value: string
value
: string = 123;
// ✅ Valid - description matches format
// @ts-expect-error: TS2322 because we need to test this
const
const value: string
value
: string = 123;
{
"rules": {
"ts/tsComments": {
"options": {
"allowTsExpectError": "allow-with-description",
"allowTsIgnore": true,
"allowTsNocheck": true,
"minimumDescriptionLength": 10
}
}
}
}

If you have legacy code with many @ts-ignore comments that you cannot immediately migrate, you may want to disable this rule temporarily.

Made with ❤️‍🔥 around the world by the Flint team and contributors.