vue/require-prop-type-constructor 正确性
它的作用
要求 props 的类型值使用构造函数(例如 String、 Number、Boolean),而不是字符串、数字或其他字面量。
为什么这不好?
Vue 会使用 prop 类型进行运行时校验和开发时警告。像 'String' 这样的字符串看起来像构造函数,但永远不会与实际值匹配, 从而静默地禁用了检查。
示例
以下是此规则的错误代码示例:
vue
<script>
export default {
props: {
foo: "String",
bar: { type: "Number" },
},
};
</script>以下是此规则的正确代码示例:
vue
<script>
export default {
props: {
foo: String,
bar: { type: Number },
},
};
</script>如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vue"],
"rules": {
"vue/require-prop-type-constructor": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["vue"],
rules: {
"vue/require-prop-type-constructor": "error",
},
});bash
oxlint --deny vue/require-prop-type-constructor --vue-plugin版本
此规则于 v1.68.0 中添加。
