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?
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!
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.
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.
If you are using ESLint and you need to disable the next line, use this code: eslint-disable-next-line.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With