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.

Allow for passing null / undefined into a typed, none required prop

See original GitHub issue

If 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:closed
  • Created 8 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rmp135commented, Mar 5, 2016

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.

0reactions
lopugitcommented, Oct 10, 2017

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

Read more comments on GitHub >

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

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