ESLint no-unused-vars Rule for TypeScript
The default no-unused-vars
complains even for parameters in interface declarations. It does not mean you have to write an eslint-disable
comment or put a _
prefix for these parameters every time. There’s an extended version of this rule for TypeScript. With disabling the default no-unused-vars
and enabling @typescript-eslint/no-unused-vars
, the problem mentioned here disappears.
By the way, there’s an ESLint plugin that makes unused imports auto-fixable. This plugin uses either the default no-unused-vars
or the other one. When you use this plugin for TypeScript projects, you should make sure @typescript-eslint/eslint-plugin
and @typescript-eslint/parser
are installed. The .eslintrc
would be like the below. Otherwise, the problem above could happen. This is what I learned this time.
{
"plugins": ["unused-imports", "@typescript-eslint/eslint-plugin"],
"rules": {
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": "error"
}
}