Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add depth Option to partial for Nested Optional Attributes #1266

Open
yeoffrey opened this issue Jul 22, 2024 · 0 comments
Open

Comments

@yeoffrey
Copy link
Contributor

Description

It would be beneficial to enhance the partial function in the superstruct library to support a depth option. This option would allow attributes to be made optional up to a specified level of nested objects.

Example

import { number, object, optional, partial, string } from 'superstruct'

const MyStruct = object({
  name: string(),
  address: object({
    street: string(),
    number: number(),
  }),
})

const PartialMyStruct = partial(MyStruct, { depth: 1 })

// The same as:
// const PartialMyStruct = optional(
//   object({
//     name: optional(string()),
//     address: optional(
//       object({
//         street: string(),
//         number: number(),
//       })
//     ),
//   })
// )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant