-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Optional boolean prop gives type Ref<boolean | undefined> which should be Ref<boolean> #7487
Comments
@jacekkarczmarczyk Not really a duplicate of #7177. In fact, #7177 can be closed as it is expected behavior (#7177 (comment)). Looking at the current docs about this, the provided example there suggests to simply declare boolean props as required, as they have an implicit default, but that seems like a typo. So docs need some cleaning up as well |
The problem with that is that my IDE (JetBrains) shows me the warning that component is missing required prop if I don't provide it. Not sure if this is a problem on IDE or Vue side |
Ed it: not a typo. The example in the docs uses runtime props annotations: const props = defineProps({
disabled: Boolean
}) quivalent to a "normal" props definition: defineComponent({
props: {
disabled: Boolean
}
}) This works fine, the IDE will report it as optional in the parent, and it will be cast as But when using the generic argument instead, like in this issue, it breaks: const props = defineProps<{
disabled?: boolean
}>() This is the bug we are discussing here. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
… type of defineProps (vuejs#7619) close vuejs#7116 fix vuejs#5847 fix vuejs#7487
… type of defineProps (vuejs#7619) close vuejs#7116 fix vuejs#5847 fix vuejs#7487
Vue version
3.2.45
Link to minimal reproduction
https://sfc.vuejs.org/#eNp9kN1qwzAMhV9F+KYbNDa7DW7H2AvsAXyTpkqTEv8gOy0j+N0npz9sHfTO50j6ZJ1ZfIQgTxOKWujY0hASRExT2Bo32OApwQyEHWToyFtYcevqXvr0Nlx9qYooJC5rdUExhEVCG8YmISsAvcwofmt1L4i1uBAr2wR5jN7xd+bSbq6FaEQNi1M83lK0EX1KIdZKxa4tq49RejoofkmaXBosSoy22pE/RyQGG7H+xVBsnpAqQrdHQnrGfGj9xy3YbFzmU25BPEYKY+MOGyPKMXx/611MEMiHCBvYYzc4/CpKL3fG3p/fa9h5P2LDMebty+vzZPu37Twvc5AzVMAifQf03c3Tilv+Bp9/APuhswM=
Steps to reproduce
Here, we get
show
type asRef<boolean>
however in VS Code it isRef<boolean | undefined>
🤔What is expected?
It should have property type as Ref according to this: https://vuejs.org/guide/components/props.html#prop-validation
What is actually happening?
It is getting type as
Ref<boolean|undefined>
whereundefined
is invalid.System Info
Any additional comments?
Original Issue: vuejs/language-tools#2219
The text was updated successfully, but these errors were encountered: