In all my TypeScript projects, I utilize ESLint with specific settings in place:
"extends": ["airbnb", "prettier", 'plugin:vue/recommended'],
"plugins": ["prettier"],
"parserOptions": {
"parser": "@typescript-eslint/parser",
"ecmaVersion": 2018,
"sourceType": "module"
},
Along with a set of custom rules, I've also integrated the following dependencies for TypeScript support:
"@typescript-eslint/eslint-plugin": "^1.7.0", "@typescript-eslint/parser": "^1.7.0",
However, I have encountered a hurdle with one of ESLint's most valuable rules, https://eslint.org/docs/rules/no-unused-vars, specifically when it comes to TypeScript projects. For instance, the rule triggers warnings when I export an enum, stating that the enum is not being used within the same file:
export enum Foo {
Bar,
}
Similarly, when importing an interface or class to be used as a type, 'no-unused-vars' also prompts warnings at the import statement:
In Foo.ts
export interface Foo {
bar: string;
}
In bar.ts
import { Foo } from './Foo'
const bar: Foo = { bar: 'Hello' };
Is there a way to configure the no-unused-vars rule to address these scenarios? I prefer not to disable the rule, as it is generally beneficial in my ruleset apart from these instances.
Even after downgrading the rule to a warning instead of an error, having warnings scattered throughout my documents diminishes the purpose of using ESLint.
Adding //eslint-disable-line to all my documents as recommended here does not seem like an ideal solution either.