useVueConsistentDefinePropsDeclaration (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.3.11 - Diagnostic Category:
lint/style/useVueConsistentDefinePropsDeclaration - This rule isn’t recommended, so you need to enable it.
- This rule doesn’t have a fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
- Sources:
- Same as
vue/define-props-declaration
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "style": { "useVueConsistentDefinePropsDeclaration": "error" } } }}Description
Section titled “Description”Enforce a consistent declaration style for Vue’s defineProps macro.
Vue accepts two ways to declare component properties: a TypeScript type passed between
angle brackets, or a runtime object passed as an argument. This rule enforces one style
throughout the project. The default style is type.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<script setup lang="ts">const props = defineProps({ kind: { type: String },});</script>code-block.vue:2:15 lint/style/useVueConsistentDefinePropsDeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This defineProps declaration uses runtime declaration.
1 │ <script setup lang="ts">
> 2 │ const props = defineProps({
│ ^^^^^^^^^^^^^
> 3 │ kind: { type: String },
> 4 │ });
│ ^^
5 │ </script>
6 │
ℹ It should be defined using type declaration like defineProps<...>().
<script setup lang="ts">const props = defineProps<{ kind: string;}>();</script>Options
Section titled “Options”Selects type or runtime declarations. Defaults to type.
{ "linter": { "rules": { "style": { "useVueConsistentDefinePropsDeclaration": { "level": "on", "options": { "style": "runtime" } } } } }}With runtime, a type-based declaration is invalid:
<script setup lang="ts">const props = defineProps<{ kind: string }>();</script>code-block.vue:2:15 lint/style/useVueConsistentDefinePropsDeclaration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This defineProps declaration uses type declaration.
1 │ <script setup lang="ts">
> 2 │ const props = defineProps<{ kind: string }>();
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 │ </script>
4 │
ℹ It should be defined using runtime declaration like defineProps(...).
A runtime declaration is valid:
<script setup lang="ts">const props = defineProps({ kind: { type: String } });</script>Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.