question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multi-type prop validation is not consistent

See original GitHub issue

Vue.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:closed
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
defcccommented, Oct 9, 2016

getType func seems not to deal with multi-type props, it just returns the first type

I will try to make a pr

0reactions
posvacommented, Oct 10, 2016

I’ll share the rest of the team.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found