Skip to content

noVueRequiredPropWithDefault (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noVueRequiredPropWithDefault": "error"
}
}
}
}

Disallow props that are both required and have a default value.

A prop with a default value can be omitted, because Vue falls back to the default value. Marking such a prop as required is contradictory: parent components are expected to always pass a required prop, so its default value should never be needed.

This rule checks props declared with the props option, with defineProps(), and with type-based defineProps<T>() whose defaults are provided through withDefaults() or props destructuring.

<script setup lang="ts">
const props = withDefaults(
defineProps<{
name: string;
}>(),
{
name: "Foo",
},
);
</script>
code-block.vue:4:5 lint/nursery/noVueRequiredPropWithDefault  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ The prop name is required, but it also has a default value.

2 │ const props = withDefaults(
3 │ defineProps<{
> 4 │ name: string;
│ ^^^^^^^^^^^^^
5 │ }>(),
6 │ {

ℹ The default value is declared here.

5 │ }>(),
6 │ {
> 7 │ name: "Foo",
│ ^^^^^^^^^^^
8 │ },
9 │ );

ℹ Parent components are expected to always pass a required prop, so its default value should never be needed.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Make the prop optional.

4 │ ····name?:·string;
│ +
<script setup lang="ts">
const { name = "Foo" } = defineProps<{
name: string;
}>();
</script>
code-block.vue:3:3 lint/nursery/noVueRequiredPropWithDefault  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ The prop name is required, but it also has a default value.

1 │ <script setup lang="ts">
2 │ const { name = "Foo" } = defineProps<{
> 3 │ name: string;
│ ^^^^^^^^^^^^^
4 │ }>();
5 │ </script>

ℹ The default value is declared here.

1 │ <script setup lang="ts">
> 2 │ const { name = "Foo" } = defineProps<{
│ ^^^^^^^^^^^^
3 │ name: string;
4 │ }>();

ℹ Parent components are expected to always pass a required prop, so its default value should never be needed.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Make the prop optional.

3 │ ··name?:·string;
│ +
<script>
export default {
props: {
name: {
required: true,
default: "Foo",
},
},
};
</script>
code-block.vue:5:7 lint/nursery/noVueRequiredPropWithDefault  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ The prop name is required, but it also has a default value.

3 │ props: {
4 │ name: {
> 5 │ required: true,
│ ^^^^^^^^^^^^^^
6 │ default: "Foo",
7 │ },

ℹ The default value is declared here.

4 │ name: {
5 │ required: true,
> 6 │ default: "Foo",
│ ^^^^^^^^^^^^^^
7 │ },
8 │ },

ℹ Parent components are expected to always pass a required prop, so its default value should never be needed.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Make the prop optional.

3 3 │ props: {
4 4 │ name: {
5 │ - ······required:·true,
5 │ + ······required:·false,
6 6 │ default: "Foo",
7 7 │ },

<script setup lang="ts">
const props = withDefaults(
defineProps<{
name?: string;
age: number;
}>(),
{
name: "Foo",
},
);
</script>
<script setup>
const props = defineProps({
name: {
required: false,
default: "Foo",
},
age: {
required: true,
},
});
</script>