Subscribe on changes!

Component's `props` cannot correctly validate `required` on a Boolean prop

avatar
Mar 5th 2021

Version

3.0.7

Reproduction link

https://jsfiddle.net/cafpskt5/22/ Screenshot_20210305_100533

Steps to reproduce

  1. Define a required boolean prop in component (e.g. bool: { type: Boolean, required: true } in props)
  2. Use this component, but don't pass any prop to it.

What is expected?

Gives a warning [Vue warn]: Missing required prop: \"bool\""

What is actually happening?

No warning message output.


  1. But if you give :bool= a string or number, it indeed can be validated and gives a warning message ([Vue warn]: Invalid prop: type check failed for prop \"bool\". Expected Boolean, got String with value \"1\".).
  2. Other types (Number, String, Object) work well and have no similar bugs like this.
avatar
Mar 5th 2021

bool is set to false by default. is this about #3337 ?

avatar
Mar 5th 2021

Yeah, by default if the boolean props are absent then they will be cast to false, but we still need to raise a warning if it is required.