script/require-prop-types
Require every prop to declare a type.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
error |
opinionated |
No | None |
Applies to: JS/TS scripts in Vue SFCs; examples show the relevant Options API or script setup form.
Bad
The array entry declares only the name status; the null value and empty descriptor declare no runtime prop type either.
<script lang="ts">
export default {
props: ['status'] // array form: no types
}
export default {
props: {
status: null, // no type
other: {} // empty descriptor: no type
}
}
</script>
Good
status: String supplies a shorthand constructor, and other supplies type: Number inside its descriptor. Both props now carry type declarations.
<script lang="ts">
export default {
props: {
status: String,
other: { type: Number, default: 0 }
}
}
</script>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"script/require-prop-types": "error"
}
},
});
Then run vp run lint.