Description
What rule do you want to change?
vue/require-default-prop
Does this change cause the rule to produce more or fewer warnings?
This change will produce fewer warnings. Specifically, it will stop producing warnings for optional props that are not included in the destructuring pattern when using Vue 3.5's props destructuring syntax.
How will the change be implemented? (New option, new default behavior, etc.)?
New default behavior - no new options needed. The rule will be modified to check if an optional prop is actually destructured before requiring a default value. If an optional prop is not included in the destructuring pattern, it won't require a default value.
Please provide some example code that this change will affect:
<script setup lang="ts">
// Case 1: Optional prop NOT destructured - should NOT require default (new behavior)
const { requiredProp } = defineProps<{
requiredProp: string;
optionalNotUsed?: string; // ← This should NOT cause an error
}>()
// Case 2: Optional prop IS destructured - should require default (existing behavior)
const { requiredProp, optionalUsed } = defineProps<{
requiredProp: string;
optionalUsed?: string; // ← This should still cause an error without default
}>()
// Case 3: Correct usage with defaults
const { requiredProp, optionalUsed = 'default' } = defineProps<{
requiredProp: string;
optionalUsed?: string;
}>()
</script>
What does the rule currently do for this code?
Currently, the rule produces warnings for ALL optional props when using props destructuring, even if they are not included in the destructuring pattern. This is unnecessarily verbose and forces developers to destructure props they don't need just to assign = undefined
.
Example of current behavior:
// Current: Forces unnecessary destructuring
const { requiredProp, optionalNotUsed = undefined } = defineProps<{
requiredProp: string;
optionalNotUsed?: string; // Must be destructured even if not used
}>()
What will the rule do after it's changed?
After the change, the rule will only require default values for optional props that are actually included in the destructuring pattern. Optional props that are not destructured will be ignored by this rule, allowing for cleaner and more intuitive code.
Additional context
This change addresses the regression introduced in version 10.1.0 as reported in issues #2725 and #2741.
Background from #2725:
The original issue was that vue/require-default-prop
didn't trigger with props destructure at all. This was fixed in PR #2728, but the fix was too strict and started requiring default values for ALL optional props, even those not used in destructuring.
Background from #2741:
Users reported a regression where they had to destructure all optional props and assign = undefined
even when those props were only used in templates, leading to unnecessarily verbose code.
The Problem:
// Before the fix in #2728: No warnings (incorrect)
const { msg } = defineProps<{ msg?: string }>()
// After the fix in #2728: Requires unnecessary defaults (too strict)
const { used, unused = undefined } = defineProps<{
used?: string;
unused?: string; // unused in script, only in template
}>()
Proposed Solution:
Only require default values for optional props that are explicitly included in the destructuring pattern:
// Should NOT warn (unused is not destructured)
const { used } = defineProps<{
used?: string; // ← Should warn (destructured without default)
unused?: string; // ← Should NOT warn (not destructured)
}>()
// Should warn only for 'used'
// Should NOT warn for 'unused'
This approach maintains the intent of the original fix while avoiding the verbose regression that affects users who don't destructure all their optional props.