diff --git a/lib/rules/require-typed-ref.js b/lib/rules/require-typed-ref.js
index 60a82432a..c05e6c829 100644
--- a/lib/rules/require-typed-ref.js
+++ b/lib/rules/require-typed-ref.js
@@ -44,13 +44,23 @@ module.exports = {
return {}
}
- const scriptSetup = utils.getScriptSetupElement(context)
- if (
- scriptSetup &&
- !utils.hasAttribute(scriptSetup, 'lang', 'ts') &&
- !utils.hasAttribute(scriptSetup, 'lang', 'typescript')
- ) {
- return {}
+ if (utils.isVueFile(filename)) {
+ const sourceCode = context.getSourceCode()
+ const documentFragment =
+ sourceCode.parserServices.getDocumentFragment &&
+ sourceCode.parserServices.getDocumentFragment()
+ if (!documentFragment) {
+ return {}
+ }
+ const scripts = documentFragment.children.filter(
+ /** @returns {element is VElement} */
+ (element) => utils.isVElement(element) && element.name === 'script'
+ )
+ if (
+ scripts.every((script) => !utils.hasAttribute(script, 'lang', 'ts'))
+ ) {
+ return {}
+ }
}
const defines = iterateDefineRefs(
diff --git a/tests/lib/rules/require-typed-ref.js b/tests/lib/rules/require-typed-ref.js
index 6e8797943..5b18bcb3c 100644
--- a/tests/lib/rules/require-typed-ref.js
+++ b/tests/lib/rules/require-typed-ref.js
@@ -86,6 +86,20 @@ tester.run('require-typed-ref', rule, {
`,
languageOptions: { parser: require('vue-eslint-parser') }
},
+ {
+ filename: 'test.vue',
+ code: `
+
+ `,
+ languageOptions: { parser: require('vue-eslint-parser') }
+ },
{
filename: 'test.js',
code: `
@@ -217,6 +231,30 @@ tester.run('require-typed-ref', rule, {
],
languageOptions: { parser: require('vue-eslint-parser') }
},
+ {
+ filename: 'test.vue',
+ code: `
+
+ }
+ `,
+ errors: [
+ {
+ messageId: 'noType',
+ line: 6,
+ column: 29,
+ endLine: 6,
+ endColumn: 34
+ }
+ ],
+ languageOptions: { parser: require('vue-eslint-parser') }
+ },
{
filename: 'test.ts',
code: `