When an optional prop is a boolean, never use true
as a default value
#741
Unanswered
justinrlle
asked this question in
PrimeVue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First, let me thank you for your work on Primevue, it's truly a joy to use and integrate, and it's really flexible!
My issue is because in Vue, unless explicitly specified,
false
is used instead ofundefined
for boolean properties (cf the documentation on properties)This means that if I want to wrap around a component from
primevue
and type it by usingdefineProps<ComponentProps>()
, I must specify all the properties defaulting totrue
inprimevue
and keep up with it.For example, I'm wrapping around OverlayPanel to easily provide a toggle, and this the code I have to write (with some non-related functionality removed):
Only using
false
for default values would also have the benefit that all boolean properties can be used without a value (most of the time) (<OverlayPanel disable-auto-z-index />
for exemple)I'm not sure this is doable: not only this means a massive renaming of all concerned props to invert their names, like
disable-auto-z-index
in theOverlayPanel
case), but it might also means a departure from API compatibility withPrimeReact
andPrimeNg
and others.Unfortunately, it's currently impossible to use
withDefault
with an object given from some other place, so I can't import a magic object from you to correctly define the defaults.Honestly, this is not a big issue, but your lib has been a pleasure to use and integrate, so of course I had to give a feedback on small issue 😉
Beta Was this translation helpful? Give feedback.
All reactions