Subscribe on changes!

Boolean props default value is not undefined

avatar
May 5th 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:")

avatar
May 5th 2022

Related Issues #5847

avatar
May 5th 2022

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

avatar
May 5th 2022

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

avatar
May 8th 2022

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

avatar
May 8th 2022

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