-
-
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
toRefs type is wrong when using defineProps with optional boolean props #5847
Comments
In this test case if the props type is Boolean, absent should cast to false. |
Interesting, I tend to think this is a bug, since other primitive type's default value is |
If it's a bug,it's easy to fix,change the handling of this situation // boolean casting
if (opt[BooleanFlags.shouldCast]) {
if (isAbsent && !hasDefault) {
value = false
} else if (
opt[BooleanFlags.shouldCastTrue] &&
(value === '' || value === hyphenate(key))
) {
value = true
}
} to // boolean casting
if (opt[BooleanFlags.shouldCast]) {
if (isAbsent && !hasDefault) {
value = undefined
} else if (
opt[BooleanFlags.shouldCastTrue] &&
(value === '' || value === hyphenate(key))
) {
value = true
}
} but in this test case if the props type is Boolean, absent should cast to false. |
If is a not a bug, why we need this behaviour, what is the motivation of this design? It is kind of odd and inconsistent to other types. IMO, absent value should always be I noticed that only boolean props will do the casting, other types will just remain |
@StephenChips I think there are two different moments: |
Even when using withDefaults setting the prop to undefined, the type becomes Is there any workaround to use watchers on props without using toRefs ? |
The problem is still there, I thought it was a little ugly to put an additional check, hope it will be fixed soon |
… 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
Version
3.2.26
Reproduction link
stackblitz.com
Steps to reproduce
What is expected?
According to fix(runtime-core): ensure declare prop keys are always present type of
isLive
should be:What is actually happening?
The type of
isLive
actually is:isLive
couldn't be undefined in no caseThe text was updated successfully, but these errors were encountered: