Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how ignore typescript errors with @ts-ignore?

I have a case where I'm importing a puraly JavaScript library within TypeScript project giving me the nagging Could not find a declaration file for module xxx message. So after reading I found I can supress that with a comment with @ts-ignore. Yet adding that comment before the offending line, I get another error

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

How can I fix this error and suppress the original message?

like image 971
saz Avatar asked Jan 14 '20 08:01

saz


People also ask

How do I tell TypeScript to ignore a line?

Use the // @ts-ignore comment to disable type checking for a line in TypeScript. The comment disables type checking for the next line. If you use a linter, you might need to disable it for the line on which you use the // @ts-ignore comment. Copied!

What is the use of TS ignore?

A // @ts-ignore comment suppresses all errors that originate on the following line. It is recommended practice to have the remainder of the comment following @ts-ignore explain which error is being suppressed.

How do I turn off TypeScript for one line?

To disable a TypeScript rule for a specific line, we can use the @ts-ignore comment. to add the // @ts-ignore: Unreachable code error comment so that the TypeScript compiler ignores the unreachable code error in the line after the comment.

How do I disable TypeScript Eslint?

If you are using ESLint and you need to disable the next line, use this code: eslint-disable-next-line.


1 Answers

You can stop using @ts-ignore

Or you can disable the eslint rule. Add that in your eslint config (.eslintrc or equivalent)

...   "rules": {     "@typescript-eslint/ban-ts-ignore": "off"   } ... 

EDIT: If you are using @typescript-eslint/eslint-plugin version 2.18 or higher, the rule is called ban-ts-comment and you need to add

"@typescript-eslint/ban-ts-comment": "off" 

instead. Here is the changelog

like image 193
ThomasThiebaud Avatar answered Sep 19 '22 23:09

ThomasThiebaud