vue/define-props-declaration 风格
它的作用
此规则强制使用 defineProps 的类型声明风格,您应使用基于类型的声明或运行时声明。 此规则仅在带有 lang="ts" 的 <script setup> 中生效。
为什么这是不好的?
不一致的代码风格可能令人困惑,使代码更难阅读。
示例
以下为该规则的 错误 代码示例:
vue
// "vue/define-props-declaration": ["error", "type-based"]
<script setup lang="ts">
const props = defineProps({
kind: { type: String },
});
</script>
// "vue/define-props-declaration": ["error", "runtime"]
<script setup lang="ts">
const props = defineProps<{
kind: string;
}>();
</script>以下为该规则的 正确 代码示例:
vue
// "vue/define-props-declaration": ["error", "type-based"]
<script setup lang="ts">
const props = defineProps<{
kind: string;
}>();
</script>
// "vue/define-props-declaration": ["error", "runtime"]
<script setup lang="ts">
const props = defineProps({
kind: { type: String },
});
</script>配置
此规则接受以下字符串值之一:
"type-based"
强制使用基于类型的声明。
"runtime"
强制使用运行时声明。
如何使用
要通过配置文件或 CLI 启用 此规则,可以使用:
json
{
"plugins": ["vue"],
"rules": {
"vue/define-props-declaration": "error"
}
}bash
oxlint --deny vue/define-props-declaration --vue-plugin