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?
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
All answers here suggest disabling the whole eslint rule which is not very practical, a better solution will be to ignore the eslint error at that specific location like this:
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Posting as an answer instead of comment to the accepted answer because of my lack of reputation. I still want to contribute and possibly help someone out.
The rule for me was
@typescript-eslint/ban-ts-comment
not ban-ts-ignore