abdou_behind_the_code
abdou_behind_the_code

Reputation: 519

Exclude line of code from being compiled without ts-ignore

I use ESLint with Angular v13.

I got the following lint error while using // @ts-ignore:

Do not use "// @ts-ignore" comments because they suppress compilation errors @typescript-eslint/ban-ts-ignore

Seems @typescript-eslint doesn't recommend the use of @ts-ignore.

Is there any alternative way to tell the TypeScript compiler to ignore a specific line from the code?

Upvotes: 3

Views: 3952

Answers (1)

Akasha
Akasha

Reputation: 1077

You can configure the rule @typescript-eslint/ban-ts-comment to allow a @ts-ignore comment when it comes with a description. More info here.

  1. In your code, add a description to your @ts-ignore comment:
//@ts-ignore: describe why you're using ts-ignore here
...code...
  1. In your ESLint configuration file (eslintrc.*), configure the rule accordingly:
{
  "rules": {
    "@typescript-eslint/ban-ts-comment": [
      "error",
      {
        "ts-ignore": "allow-with-description"
      }
    ]
  }
}

Upvotes: 7

Related Questions