Multi-type prop validation is not consistent
See original GitHub issueVue.js version
2.0.1
Reproduction Link
https://jsfiddle.net/alexman/f7sb0rd3/9/
Steps to reproduce
Create a component with a prop of type [String, Boolean]
and instantiate it with a boolean value or shorthand prop notation. (<my-component my-prop></my-component>
)
What is Expected?
Booleans are accepted and passed to the validator as a boolean value.
What is actually happening?
You’ll see that it will not validate booleans / shorthand prop notation.
Defining it reversed, [Boolean, String]
, does seem to work as expected except for not being able to pass false as a value.
Observations
I noticed validateProp()
does the following “magic”, which doesn’t seem to take the option of an array of types into account?
if (getType(prop.type) === 'Boolean') {
if (absent && !hasOwn(prop, 'default')) {
value = false
} else if (value === '' || value === hyphenate(key)) {
value = true
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Allow different types of PropTypes for one prop - Stack Overflow
Can I let React.PropTypes know that this can be either one or the other in the propTypes validation? If I don't specify the...
Read more >[Solved]-Vue prop validation is not called-Vue.js
I don't know the reason, but it is working if I use component tag like <tag></tag> . If I use like <tag/> ,...
Read more >How to validate React props using PropTypes - LogRocket Blog
Learn how to validate props with React PropTypes, React's internal mechanism for adding type checking to component props.
Read more >'value' is missing in props validation - You.com | The AI Search ...
The error is gone, but I want/need to use prop deconstruction. The error is probably caused by the deconstruction of the ResultListItem prop...
Read more >How You Can Fix The Biggest Problem With React File Upload
Why is a React file upload not working properly? ... Likewise, event handlers are easier to manage using an organized list of props....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
getType func seems not to deal with multi-type props, it just returns the first type
I will try to make a pr
I’ll share the rest of the team.