I'm a longtime user of TypeScripts noUnusedLocals
and noUnusedParameters
settings. I like to avoid leaving unused variables in my code; these compiler options help me do that.
I use ESLint alongside TypeScript. The no-unused-vars
rule provides similar functionality to TypeScripts noUnusedLocals
and noUnusedParameters
settings, but has more power and more flexibility. For instance, no-unused-vars
can catch unused error variables; TypeScript's noUnusedLocals
and noUnusedParameters
cannot.
One thing that I missed when switching to the ESLint option is that, with noUnusedLocals
and noUnusedParameters
, you can simply ignore unused variables by prefixing a variable with the _
character. That's right, sometimes I want to declare a variable that I know I'm not going to use, and I want to do that without getting shouted at by the linter.
It turns out you can get ESLint to respect the TypeScript default of ignoring variables prefixed with _
; it's just not the default configuration for no-unused-vars
. But with a little configuration we can have it. This post is a quick guide to how to implement that configuration.