Allow specific properties to be `.required`
See original GitHub issueI have a mySchema with ~10 properties.
In my API, I use mySchema.partial()
as all props are optional, BUT one.
I wish I could simply mySchema.partial().required({ myRequired: true })
, as partial allows.
It would be a better solution than .partial({ 9 props }) or merging with the mySchema.shape.myRequired.
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Typescript: allow any property starting with a specific string
I need to assign properties with unique names, all starting with a string, say meta_ . How do I write a type for...
Read more >Make Some Properties From a TypeScript Type Required
Learn how to construct a new type from an existing one with specific properties as required.
Read more >Required property (Access) - Microsoft Learn
Use the Required property to specify whether a value is required in a field. If this property is set to Yes, when you...
Read more >Typescript type shenanigans 2: specify at least one property
The Record-type allows types with n properties where all of the properties are of some specified type. The Partial-type makes all properties ......
Read more >Schema validation reference for object types
data.schema object has missing required properties (["properties"]). The schema does not have a properties property, which is mandatory.
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
+1 fo this, it is very common scenario.
For example I have a
orderSchema
and I have anupdateOrder()
function that takesorderSchema.partial()
(listing each key in thepartial()
function would be too tedious), but I want theorderSchema.shape.id
property to be required, so I would like to doorderSchema.partial().required({id:true})
instead of the hack I am currently usingorderSchema.partial().omit({id:true}).extend({id: orderIdSchema})
Merged in #1315