-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
undefined
type in prop could warn
#5471
Comments
The type could be If you still want to have your way of handling defineProps({ count: {
type: null,
validator: v => v === undefined || typeof v === 'number',
required: true,
}}); |
It could be I don't want to put It would be nice if Vue at least didn't show such misleading warnings.If you cannot make it work as expected, then at least don't change the type from |
Thank you for the clarification @posva!
I second this. That |
undefined
prop triggers misleading warningundefined
type in prop could warn
Found a workaround. If you want to get rid of the annoying warning, you can specify the type you want, not directly, but through a generic, for example. type AvoidValidation<T> = T
defineProps<{
modelValue: AvoidValidation<string | undefined>
}>() This is type-check friendly, you keep the ability to specify the field required. But you sacrifice the default property validation. |
Version
3.2.31
Reproduction link
sfc.vuejs.org/
Steps to reproduce
number | undefined
usingdefineProps
functionundefined
value to this propWhat is expected?
If you define prop type as
number | undefined
, there should be no warning if you passundefined
value.What is actually happening?
Vue somehow interprets the type definition as
number | null
and complains aboutundefined
not matching this type:Of course you can use
defineProps<{count?: number}>()
. But this definition doesn't make the prop required and so an IDE won't warn you if you forget to pass in the value. I want to force all consumers of my component to providecount
prop while still being able to passundefined
as a valid value.The text was updated successfully, but these errors were encountered: