Skip to content
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

Boolean props default value is not undefined #5863

Closed
beruic opened this issue May 5, 2022 · 5 comments
Closed

Boolean props default value is not undefined #5863

beruic opened this issue May 5, 2022 · 5 comments

Comments

@beruic
Copy link

beruic commented May 5, 2022

Version

3.2.31

Reproduction link

sfc.vuejs.org/

Steps to reproduce

See the minimal reproduction.

What is expected?

Both myValue and myOtherValue should be undefined by default.

What is actually happening?

myOtherValue (where only the type constructor is defined) ends up false instead.


That a Boolean ends up false by default kinda makes sense, but is also inconsistent with the documentation. All the types should all behave predictably for consistency, so either the documentation needs to specify this, or it has to be changed.

The documentation states that "An absent optional prop will have undefined value" at https://vuejs.org/guide/components/props.html#prop-validation (A bit down under "Additional details:")

@liulinboyi
Copy link
Member

Related Issues #5847

@posva
Copy link
Member

posva commented May 5, 2022

This is intended behavior. Maybe you should submit a PR with your proposal to vuejs/docs

@posva posva closed this as completed May 5, 2022
@beruic
Copy link
Author

beruic commented May 5, 2022

@posva Then I would need to know the intended behavior for all the types.

@sondh0127
Copy link

sondh0127 commented May 8, 2022

This is annoying default for boolean, while other type e.g string return undefined by default. only boolean return false?

@liulinboyi
Copy link
Member

This is annoying default for boolean, while other type e.g string return undefined by default. only boolean return false?

According to this unit test, Yes.
image

sondh0127 added a commit to sondh0127/docs that referenced this issue May 8, 2022
The Boolean missing prop will cast to false instead of undefined, vuejs/core#5863 (comment)
NataliaTepluhina pushed a commit to vuejs/docs that referenced this issue May 8, 2022
The Boolean missing prop will cast to false instead of undefined, vuejs/core#5863 (comment)
jay-es pushed a commit to vuejs-translations/docs-ja that referenced this issue May 8, 2022
The Boolean missing prop will cast to false instead of undefined, vuejs/core#5863 (comment)
jay-es added a commit to vuejs-translations/docs-ja that referenced this issue May 9, 2022
…cast to false instead of undefined, vuejs/core#5863 (comment) (#536) (#537)

* fix: update named slots diagram

Close #1688

* Correct default value for absent props. (#1705)

The Boolean missing prop will cast to false instead of undefined, vuejs/core#5863 (comment)

Co-authored-by: Natalia Tepluhina <[email protected]>
Co-authored-by: sondh0127 <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Sep 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants