ESLint v9: Should ignoreTypeReferences Default to True for TypeScript Projects?
0 reputation · 19 Apr 2022, 07:22 UTC
0 reputation · 19 Apr 2022, 07:22 UTC
Determine the appropriate default behavior for the newly documented ignoreTypeReferences option in ESLint v9’s no-unused-vars rule, especially in TypeScript codebases.
The option’s implementation depends on @typescript-eslint/parser; without it, the rule may error or misbehave. Enabling ignoreTypeReferences could mask legitimate unused‑variable warnings if type annotations are misused or omitted. The interaction with other rule settings—args, vars, and ignoreRestSiblings—has not been fully documented, leaving ambiguity about combined effects.
ignoreTypeReferences in ESLint 9?ignoreTypeReferences interact with args, vars, and ignoreRestSiblings when enabled?35275 reputation · 19 Apr 2022, 09:24 UTC
The intended default value for ignoreTypeReferences in ESLint v9's no-unused-vars rule is false. This preserves backward compatibility and keeps the rule strict for all files unless overridden.
Confirmed fact: The ESLint v9 documentation lists the option's default as false. Likely explanation: Keeping the default false avoids silently ignoring unused variables in JavaScript files where a variable might appear only in a type-like context (for example, JSDoc typedefs) or in a cast that is actually a value.
overrides block to your ESLint configuration targeting *.ts and *.tsx files.ignoreTypeReferences: true while leaving the global default unchanged.module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
rules: {
'no-unused-vars': ['error', { args: 'none', vars: 'local', ignoreRestSiblings: false }]
},
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
'no-unused-vars': ['error', { args: 'none', vars: 'local', ignoreRestSiblings: false, ignoreTypeReferences: true }]
}
}
]
};
Run the following command on a sample TypeScript file to see the effective config:
npx eslint --print-config src/example.ts | grep -A2 -B2 'no-unused-vars'You should observe ignoreTypeReferences: false in the global config and ignoreTypeReferences: true only within the overrides section.
Do not change the global default to true. Instead, use an overrides block to enable ignoreTypeReferences for TypeScript files only, keeping JavaScript checking strict. If you are unsure whether your codebase contains any JavaScript files that might be affected, run the verification step above on a representative sample before applying the override.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 19 Apr 2022, 11:28 UTC
Before configuring ignoreTypeReferences, confirm the option exists in your pinned ESLint 9 version. Recent ESLint 9 core releases do not list it in the no-unused-vars schema; the documented keys remain vars, args, caughtErrors, ignoreRestSiblings, and the *IgnorePattern fields.
Type-reference awareness is normally provided by @typescript-eslint/no-unused-vars with parserOptions.project enabled, not by a core boolean. In mixed repositories, keep the base rule for JavaScript and switch to the plugin rule for TypeScript files through flat-config overrides.
You can inspect the active schema with node -e "const {Linter}=require('eslint');const l=new Linter();console.log(JSON.stringify(l.getRules().get('no-unused-vars').meta.schema,null,2))" and grep for the key.