50

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?

0

3 Answers 3

59

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.

2
  • 4
    FYI - 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
32

It is now possible to use _ for unused params.

function myFunc(_, b: string) {}
function otherFunc(_, _1, c: string) {} // multiple unsused

https://github.com/Microsoft/TypeScript/issues/9458

0
6

For me, this works to suppress an "unused variable" warning in a React project:

// eslint-disable-next-line @typescript-eslint/no-unused-vars 

Not the answer you're looking for? Browse other questions tagged or ask your own question.