How to create optional object with required fields?
See original GitHub issueHi, is it possible to create the following schema:
yup.object({
foo: yup.object({
bar: yup.string().required()
})
})
where you can either provide foo
or not, but if you do, you must provide bar
? Running the above schema on {}
, I’m getting foo.bar is required
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Guide To Java 8 Optional | Baeldung
There are several ways of creating Optional objects. To create an empty Optional object, we simply need to use its empty() static method:....
Read more >Java Optional Tutorial with Examples - CalliCoder
1. Create an empty Optional. An empty Optional Object describes the absence of a value. · 2. Create an Optional with a non-null...
Read more >3 Different ways to create Java 8 Optional object with examples
This blog explains 3 different ways to create java 8 optional object with real life examples. Most common ways are using empty, ...
Read more >How to use Optional in Java - Developer.com
Once you have created an Optional object, you can use the isPresent() method to check if it contains a non-null value. If it...
Read more >How to make a field optional? - java - Stack Overflow
5. There is no concept for this in Java. Most people would just assign null to it and return Optional<String> on methods that...
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
const parent = object({ child: object({ name: string.required() }).default(undefined) })
Objects automatically default there fields which is why its complaining. If you want the object to be optional and empty by default set
.default()
to null or undefined on the foo object schema