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

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

Closed
kuanyui opened this issue Mar 5, 2021 · 2 comments · Fixed by #3363
Closed

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

kuanyui opened this issue Mar 5, 2021 · 2 comments · Fixed by #3363
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. 🐞 bug Something isn't working

Comments

@kuanyui
Copy link

kuanyui commented Mar 5, 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.
@HcySunYang HcySunYang added 🐞 bug Something isn't working 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Mar 5, 2021
@Kingbultsea
Copy link
Contributor

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

@HcySunYang
Copy link
Member

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.

@kuanyui kuanyui changed the title Component props cannot correctly validate required on a Boolean prop Component's props cannot correctly validate required on a Boolean prop Mar 5, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Oct 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. 🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants