Allow for passing null / undefined into a typed, none required prop
See original GitHub issueIf a prop is declared with type validation but required:false
, the validation will fail when passing either null or undefined as the value.
I think that the type validation should only occur on none required props if an actual value (not null or undefined) has been passed. I believe this is similar to issue #1070.
Here’s a JSBin demonstrating this.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
VueJS Using Prop Type Validation With NULL and 'undefined ...
Basic type check ( null and undefined values will pass any type validation). This applies only when required: true is NOT set. In...
Read more >vue props type null - You.com | The Search Engine You Control
If a prop is declared with type validation but required:false, the validation will fail when passing either null or undefined as the value....
Read more >Documentation - TypeScript 2.0
Null - and undefined-aware types. TypeScript has two special types, Null and Undefined, that have the values null and undefined respectively.
Read more >Solved: `value` prop on `input` should not be null in React
The warning " value prop on input should not be null" is caused when we set an initial value for an input to...
Read more >Null and undefined (Reference) - Prisma
How Prisma Client handles null and undefined, including a GraphQL use case. ... (a mandatory field) to undefined - which means ✓ do...
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 Free
Top 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
Thanks. I was going to suggest a
nullable
prop option for allowing nulls to be passed down in the case of none required props. In this case, the default would only apply if the prop was completely absent.// check default value if (value === undefined) { value = getPropDefaultValue(vm, prop, key); // since the default value is a fresh copy, // make sure to observe it. var prevShouldConvert = observerState.shouldConvert; observerState.shouldConvert = true; observe(value); observerState.shouldConvert = prevShouldConvert; } { assertProp(prop, key, value, vm, absent); }
I found this bit in vue.js v2 dist, is it around this part that defaults are now handled?
I can’t find a comment of
Build a function that applies props to a vm.
anywhere in the current v2 vue.js build