Understanding Default Behavior of Optional Boolean Props for Vue 4 #12345
stephenjason89
started this conversation in
Polls
Replies: 2 comments 3 replies
-
I think there's another option that we don't provide |
Beta Was this translation helpful? Give feedback.
1 reply
-
I've updated the poll to incorporate @Justineo's comment. Please feel free to recast your votes, as this update has reset the poll. Thank you! |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In Vue 3, when declaring an optional boolean prop using
defineProps
with TypeScript syntax (e.g.,{ isVisible?: boolean }
), the prop defaults tofalse
if it’s not provided by the parent component. This behavior contrasts with typical TypeScript expectations, where optional properties default toundefined
, which helps developers distinguish between an unset value and an explicitfalse
.Purpose of this Poll
This poll seeks feedback from the Vue community on whether optional boolean props should default to
false
orundefined
. By gathering community preferences and understanding any challenges this default behavior may present, we can evaluate whether there is strong support for a recommendation to the Vue team to consider changes.Approach
To address this, the project will:
undefined
or using nullable types.Goal
The ultimate goal of this POL is to contribute to a discussion on best practices for handling optional boolean props. By aligning with community expectations, we hope to enhance consistency and flexibility in Vue 3 components and potentially influence future updates in the Vue framework.
8 votes ·
Beta Was this translation helpful? Give feedback.
All reactions