diff --git a/packages/eslint-plugin/src/util/collectUnusedVariables.ts b/packages/eslint-plugin/src/util/collectUnusedVariables.ts index 4d1b62b42341..4df1a178fbdb 100644 --- a/packages/eslint-plugin/src/util/collectUnusedVariables.ts +++ b/packages/eslint-plugin/src/util/collectUnusedVariables.ts @@ -426,9 +426,7 @@ function isMergableExported(variable: TSESLint.Scope.Variable): boolean { * @returns True if the variable is exported, false if not. */ function isExported(variable: TSESLint.Scope.Variable): boolean { - const definition = variable.defs[0]; - - if (definition) { + return variable.defs.some(definition => { let node = definition.node; if (node.type === AST_NODE_TYPES.VariableDeclarator) { @@ -438,8 +436,7 @@ function isExported(variable: TSESLint.Scope.Variable): boolean { } return node.parent!.type.indexOf('Export') === 0; - } - return false; + }); } /** diff --git a/packages/eslint-plugin/tests/rules/no-unused-vars/no-unused-vars.test.ts b/packages/eslint-plugin/tests/rules/no-unused-vars/no-unused-vars.test.ts index e891452136a2..2646f3ce55bc 100644 --- a/packages/eslint-plugin/tests/rules/no-unused-vars/no-unused-vars.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unused-vars/no-unused-vars.test.ts @@ -1080,6 +1080,18 @@ export class Foo { typescript: '4.4', }, }, + ` +interface Foo { + bar: string; +} +export const Foo = 'bar'; + `, + ` +export const Foo = 'bar'; +interface Foo { + bar: string; +} + `, ], invalid: [ @@ -1805,5 +1817,25 @@ x = foo(x); }, ], }, + { + code: ` +interface Foo { + bar: string; +} +const Foo = 'bar'; + `, + errors: [ + { + messageId: 'unusedVar', + line: 5, + column: 7, + data: { + varName: 'Foo', + action: 'assigned a value', + additional: '', + }, + }, + ], + }, ], });