diff --git a/.changeset/lemon-turtles-visit.md b/.changeset/lemon-turtles-visit.md
new file mode 100644
index 000000000..ecff18727
--- /dev/null
+++ b/.changeset/lemon-turtles-visit.md
@@ -0,0 +1,5 @@
+---
+'eslint-plugin-vue': patch
+---
+
+Fixed false positives in `vue/define-props-destructuring` rule when imported types are passed to `defineProps`
diff --git a/lib/rules/define-props-destructuring.js b/lib/rules/define-props-destructuring.js
index 65ec1dcd7..c9e1e894b 100644
--- a/lib/rules/define-props-destructuring.js
+++ b/lib/rules/define-props-destructuring.js
@@ -40,8 +40,10 @@ module.exports = {
return utils.compositingVisitors(
utils.defineScriptSetupVisitor(context, {
onDefinePropsEnter(node, props) {
- const hasNoArgs = props.filter((prop) => prop.propName).length === 0
- if (hasNoArgs) {
+ const hasArgs = props.some(
+ (prop) => prop.propName || (prop.type === 'unknown' && prop.node)
+ )
+ if (!hasArgs) {
return
}
diff --git a/tests/lib/rules/define-props-destructuring.js b/tests/lib/rules/define-props-destructuring.js
index ce8f3db97..37d443395 100644
--- a/tests/lib/rules/define-props-destructuring.js
+++ b/tests/lib/rules/define-props-destructuring.js
@@ -44,6 +44,30 @@ tester.run('define-props-destructuring', rule, {
parserOptions: { parser: require.resolve('@typescript-eslint/parser') }
}
},
+ {
+ filename: 'test.vue',
+ code: `
+
+ `,
+ languageOptions: {
+ parserOptions: { parser: require.resolve('@typescript-eslint/parser') }
+ }
+ },
+ {
+ filename: 'test.vue',
+ code: `
+
+ `,
+ languageOptions: {
+ parserOptions: { parser: require.resolve('@typescript-eslint/parser') }
+ }
+ },
{
filename: 'test.vue',
code: `
@@ -73,6 +97,32 @@ tester.run('define-props-destructuring', rule, {
languageOptions: {
parserOptions: { parser: require.resolve('@typescript-eslint/parser') }
}
+ },
+ {
+ filename: 'test.vue',
+ code: `
+
+ `,
+ options: [{ destructure: 'never' }],
+ languageOptions: {
+ parserOptions: { parser: require.resolve('@typescript-eslint/parser') }
+ }
+ },
+ {
+ filename: 'test.vue',
+ code: `
+
+ `,
+ options: [{ destructure: 'never' }],
+ languageOptions: {
+ parserOptions: { parser: require.resolve('@typescript-eslint/parser') }
+ }
}
],
invalid: [
@@ -167,6 +217,48 @@ tester.run('define-props-destructuring', rule, {
}
]
},
+ {
+ filename: 'test.vue',
+ code: `
+
+ `,
+ languageOptions: {
+ parserOptions: { parser: require.resolve('@typescript-eslint/parser') }
+ },
+ errors: [
+ {
+ messageId: 'preferDestructuring',
+ line: 4,
+ column: 21,
+ endLine: 4,
+ endColumn: 41
+ }
+ ]
+ },
+ {
+ filename: 'test.vue',
+ code: `
+
+ `,
+ languageOptions: {
+ parserOptions: { parser: require.resolve('@typescript-eslint/parser') }
+ },
+ errors: [
+ {
+ messageId: 'preferDestructuring',
+ line: 4,
+ column: 21,
+ endLine: 4,
+ endColumn: 42
+ }
+ ]
+ },
{
filename: 'test.vue',
code: `
@@ -223,6 +315,50 @@ tester.run('define-props-destructuring', rule, {
endColumn: 54
}
]
+ },
+ {
+ filename: 'test.vue',
+ code: `
+
+ `,
+ options: [{ destructure: 'never' }],
+ languageOptions: {
+ parserOptions: { parser: require.resolve('@typescript-eslint/parser') }
+ },
+ errors: [
+ {
+ messageId: 'avoidDestructuring',
+ line: 4,
+ column: 23,
+ endLine: 4,
+ endColumn: 43
+ }
+ ]
+ },
+ {
+ filename: 'test.vue',
+ code: `
+
+ `,
+ options: [{ destructure: 'never' }],
+ languageOptions: {
+ parserOptions: { parser: require.resolve('@typescript-eslint/parser') }
+ },
+ errors: [
+ {
+ messageId: 'avoidDestructuring',
+ line: 4,
+ column: 23,
+ endLine: 4,
+ endColumn: 44
+ }
+ ]
}
]
})