mixed.oneOf doesn't respect nullable
See original GitHub issueThe 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:
- Created 6 years ago
- Reactions:14
- Comments:18 (3 by maintainers)
Top 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 >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
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 addnull
to your oneOf configHa ha, imagine how many dev hours you’ve wasted just by being stubborn and not handling this case automatically inside the library code.
Next person in this issue can increment the counter.