Skip to content
← Back to rules

vue/valid-define-props Correctness

🚧 An auto-fix is planned for this rule, but not implemented at this time.

What it does

This rule checks whether the defineProps compiler macro is valid.

This rule reports the defineProps compiler macro in the following cases:

  • defineProps references a locally declared variable.
  • defineProps has both a type argument and an argument. For example: defineProps<{ /*props*/ }>({ /*props*/ })
  • defineProps is called more than once.
  • A property is defined in both defineProps and export default {}.
  • A property is defined neither in defineProps nor in export 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-plugin

Version

This rule was added in v1.15.0.

References