vue/require-prop-types Style
它的作用
此规则强制要求 props 声明包含类型定义。
为什么这不好?
在已提交的代码中,prop 定义应尽可能详细,至少要指定类型。
示例
此规则的错误代码示例:
vue
<script setup>
const props = defineProps({
name: String,
});
</script>此规则的正确代码示例:
vue
<script setup>
const props = defineProps({
name: { type: String },
});
</script>
// 或者带验证器
<script setup>
const props = defineProps({
name: {
validator: (value) => value.length > 0,
},
});
</script>如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vue"],
"rules": {
"vue/require-prop-types": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["vue"],
rules: {
"vue/require-prop-types": "error",
},
});bash
oxlint --deny vue/require-prop-types --vue-plugin版本
该规则已在 v1.69.0 中添加。
