script/require-valid-default-prop
Require a prop's default value to be valid for its declared type
Default severity: error
Presets: essential, happy-path, ecosystem, nuxt, opinionated
Automatic fix: None; review the suggested change
Applies to: JS/TS scripts in Vue SFCs; examples show the relevant Options API or script setup form
Options: No rule-specific options. Severity and preset selection are configurable.
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({
lint: {
vize: {
"preset": "incremental",
"rules": {
"script/require-valid-default-prop": "error"
}
},
},
});
vp run lint
Bad
The Number and Boolean props receive mismatched scalar defaults, and the Array and Object props use shared literal values instead of factories.
<script lang="ts">
export default {
props: {
count: { type: Number, default: '0' }, // string default for Number
enabled: { type: Boolean, default: 1 }, // non-boolean default for Boolean
items: { type: Array, default: [] }, // literal must be a factory
config: { type: Object, default: {} } // literal must be a factory
}
}
</script>
Good
The scalar defaults become 0 and false; the array and object defaults become functions returning fresh values. The [String, Number] example accepts its string default because it matches one declared type.
<script lang="ts">
export default {
props: {
count: { type: Number, default: 0 },
enabled: { type: Boolean, default: false },
items: { type: Array, default: () => [] },
config: { type: Object, default: () => ({}) },
label: { type: [String, Number], default: '' }
}
}
</script>
Good avoids this rule's finding under the configuration above; other rules may still report diagnostics.