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 specific properties to be `.required`

See original GitHub issue

I 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:closed
  • Created a year ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ivosabevcommented, Jun 28, 2022

+1 fo this, it is very common scenario.

For example I have a orderSchema and I have an updateOrder() function that takes orderSchema.partial() (listing each key in the partial() function would be too tedious), but I want the orderSchema.shape.id property to be required, so I would like to do orderSchema.partial().required({id:true}) instead of the hack I am currently using orderSchema.partial().omit({id:true}).extend({id: orderIdSchema})

0reactions
SrBrahmacommented, Oct 5, 2022

Merged in #1315

Read more comments on GitHub >

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

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