vue/valid-define-props Correctness
What it does
This rule checks whether the defineProps compiler macro is valid.
This rule reports the defineProps compiler macro in the following cases:
definePropsreferences a locally declared variable.definePropshas both a type argument and an argument. For example:defineProps<{ /*props*/ }>({ /*props*/ })definePropsis called more than once.- A property is defined in both
definePropsandexport default {}. - A property is defined neither in
definePropsnor inexport default {}.
Why is this bad?
Incorrect use of defineProps can lead to runtime errors and loss of type safety. Vue may still compile the code, but props may silently fail or the type annotations may be incorrect.
Examples
The following code examples are incorrect for this rule:
vue
<script setup>
const def = { msg: String };
defineProps(def);
</script>vue
<script setup lang="ts">
defineProps<{ msg?: string }>({ msg: String });
</script>vue
<script setup>
defineProps({ msg: String });
defineProps({ count: Number });
</script>vue
<script>
export default {
props: { msg: String },
};
</script>
<script setup>
defineProps({ count: Number });
</script>The following code examples are correct for this rule:
vue
<script setup>
defineProps({ msg: String });
</script>vue
<script setup>
defineProps(["msg"]);
</script>vue
<script setup lang="ts">
defineProps<{ msg?: string }>();
</script>vue
<script>
export default {
props: { msg: String },
};
</script>
<script setup>
defineProps();
</script>How to use
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vue"],
"rules": {
"vue/valid-define-props": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["vue"],
rules: {
"vue/valid-define-props": "error",
},
});bash
oxlint --deny vue/valid-define-props --vue-pluginVersion
This rule was added in v1.15.0.
