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.

mixed.oneOf doesn't respect nullable

See original GitHub issue

The mixed.oneOf doesn’t accept null when nullable is added.

Example
const fruitsOrNone = yup.string().oneOf(['apple', 'banana']).nullable(true)

fruitsOrNone.validate(null) // => throws ValidationError: 'this must be one the following values: apple, banana'
fruitsOrNone.validate('apple') // => apple
Expected

It’s expected to accept the value null when nullable is set on the schema.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:14
  • Comments:18 (3 by maintainers)

github_iconTop GitHub Comments

36reactions
jquensecommented, Dec 17, 2017

yes this confusing but expected. you have a contradiction between your schema on one hand you are saying its can only be ‘apple’ or ‘banana’ and on the other say it can also be null, the best way to handle this is to add null to your oneOf config

31reactions
catamphetaminecommented, May 29, 2021

Ha ha, imagine how many dev hours you’ve wasted just by being stubborn and not handling this case automatically inside the library code.

... DEV DAYS WASTED BECAUSE OF ONE OF
NOT BEING ABLE TO HANDLE NULLS PROPERLY

Next person in this issue can increment the counter.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I make a yup number accept nullable values?
Hi @xdumaine, thanks for your response. However, when the field is left as empty, the value that it returns is NaN instead of...
Read more >
schema-to-yup - npm
Build a Yup schema object to validate models from a domain model schema (JSON or GraphQL). Latest version: 1.11.13, last published: 2 months ......
Read more >
Protobuf and Null Support - ITNEXT
The oneof helps us enforce that the data can't be both null and non null. Here is how a java client would use...
Read more >
PhpStorm EAP 183.3647.13 Release Notes | Knowledge Base
PHP Lang, Bug, WI-43691, SSR: doesn't find semicolon namespaces. Bug, WI-43755, Implement method: Nullable type is lost for varargs.
Read more >
Confluent Platform Component Changelogs | Confluent ...
CIAM-2020 - Fix null string in MDSLoggingFilter; CIAM-2019 - Fix 6.x MDS builds from ... PR-2058 - DGS-2393 Fix special chars in options...
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