pageClass | sidebarDepth | title | description |
---|---|---|---|
rule-details |
0 |
vue/optional-props-using-with-defaults |
enforce props with default values to be optional |
enforce props with default values to be optional
- 🔧 The
--fix
option on the command line can automatically fix some of the problems reported by this rule.
This rule enforce props with default values to be optional. Because when a required prop declared with a default value, but it doesn't be passed value when using it, it will be assigned the default value. So a required prop with default value is same as a optional prop.
<script setup lang="ts">
/* ✓ GOOD */
const props = withDefaults(
defineProps<{
name?: string | number
age?: number
}>(),
{
name: "Foo",
}
);
/* ✗ BAD */
const props = withDefaults(
defineProps<{
name: string | number
age?: number
}>(),
{
name: "Foo",
}
);
</script>
Nothing.