diff --git a/lib/rules/no-undef-components.js b/lib/rules/no-undef-components.js index f6e66400c..4fad95f66 100644 --- a/lib/rules/no-undef-components.js +++ b/lib/rules/no-undef-components.js @@ -130,7 +130,16 @@ module.exports = { (scope) => scope.type === 'module' ) for (const variable of (moduleScope && moduleScope.variables) || []) { - scriptVariableNames.add(variable.name) + const definition = variable.defs[0] + if ( + !( + (definition.parent?.type === 'ImportDeclaration' && + definition.parent?.importKind === 'type') || + definition.node.importKind === 'type' + ) + ) { + scriptVariableNames.add(variable.name) + } } } /** diff --git a/tests/lib/rules/no-undef-components.js b/tests/lib/rules/no-undef-components.js index b3a7af106..44e53d425 100644 --- a/tests/lib/rules/no-undef-components.js +++ b/tests/lib/rules/no-undef-components.js @@ -661,6 +661,65 @@ tester.run('no-undef-components', rule, { } ] }, + { + filename: 'test.vue', + code: ` + + + + `, + parserOptions: { + ecmaVersion: 6, + sourceType: 'module', + parser: require.resolve('@typescript-eslint/parser') + }, + parser: require.resolve('vue-eslint-parser'), + errors: [ + { + message: "The '' component has been used, but not defined.", + line: 12 + }, + { + message: + "The '' component has been used, but not defined.", + line: 13 + }, + { + message: + "The '' component has been used, but not defined.", + line: 14 + }, + { + message: + "The '' component has been used, but not defined.", + line: 15 + }, + { + message: + "The '' component has been used, but not defined.", + line: 16 + }, + { + message: + "The '' component has been used, but not defined.", + line: 17 + } + ] + }, // options API { diff --git a/typings/eslint-plugin-vue/util-types/ast/es-ast.ts b/typings/eslint-plugin-vue/util-types/ast/es-ast.ts index 16a734d2e..f4dd208c3 100644 --- a/typings/eslint-plugin-vue/util-types/ast/es-ast.ts +++ b/typings/eslint-plugin-vue/util-types/ast/es-ast.ts @@ -268,6 +268,7 @@ export interface ImportDeclaration extends HasParentNode { | ImportNamespaceSpecifier )[] source: Literal & { value: string } + importKind?: 'type' | 'value' } export interface ImportSpecifier extends HasParentNode { type: 'ImportSpecifier'