Is there a way to let my code compile with ts-node even if there is unused property warnings in one line of my .ts
file without setting "noUnusedLocals": false
in my tsconfig.json
file?
3 Answers
Since TypeScript 2.6 you can suppress errors with // @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.Please note that this comment only suppresses the error reporting, and we recommend you use this comments very sparingly.
source (release notes TypeScript 2.6
If the error is an tslint error then you can disable them with
// tslint:disable-next-line
See https://palantir.github.io/tslint/usage/rule-flags/ for more information.
-
4FYI - my eslint is recommending to use
// @ts-expect-error
in preference to ignore Commented Feb 12, 2021 at 5:16 -
@charles-allen your comment should be the answer. If you'll make an answer, I'll vote for it! Commented Mar 21, 2022 at 0:46
It is now possible to use _
for unused params.
function myFunc(_, b: string) {}
function otherFunc(_, _1, c: string) {} // multiple unsused
For me, this works to suppress an "unused variable" warning in a React project:
// eslint-disable-next-line @typescript-eslint/no-unused-vars