-
-
Notifications
You must be signed in to change notification settings - Fork 679
vue/require-default-prop
is not compatible with the Composition API and @typescript-eslint/no-unnecessary-condition
#2051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I personally think at If you want the default value when not passing, you shall use |
This rule should no longer be recommended in Vue v3 rule sets, and probably not v2 with the recent 2.7 (or only off for that version). A default value cannot be specified to maintain the proper property type with JSX/TSX or setup. |
Shameless plug (and a bit off-topic): This was one of the reasons for me to create the |
Yeah, I also ended up rigging a translator system for Zod schemas into Vue prop options to expand validation in Vue. As part of that, it worked around this issue as well since the ESLint plug-in wouldn't have any clue what to do with props defined with a |
(condensed version of #2306) I ought to mention that there's a similar issue with type parameters: <script setup lang="ts">
const props = withDefaults(defineProps<{
width: number
height?: number
}>(), {
width: 100,
})
</script>
<template>
{{ props }}
</template> This also produces a warning ("Prop 'height' requires default value to be set vue/require-default-prop"). I would argue that <script setup lang="ts">
defineProps<{
width: number
height?: number
}>()
</script> |
Checklist
Tell us about your environment
Please show your full configuration:
What did you do?
src/components/DisplayMessageCorrect.vue:
src/components/DisplayMessageWrong.vue:
What did you expect to happen?
vue/require-default-prop
is not included in any of the recommended configurations or treats Composition API built components differently.Since the Composition API actually understands the following PropOption shapes as also allowing
undefined
to be the value type seen within the component:String
{ type: String }
{ type: String, required: false }
Adding
default
orrequired: true
; the only ways to fix the warning from this rule, results in the extracted property type to no longer include undefined, the rule is inappropriate for the Composition API.What actually happened?
The following code will results in:
Repository to reproduce this issue
https://github.com/6XGate/vue-require-default-prop
The text was updated successfully, but these errors were encountered: