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

Graceful z.array() #3922

Open
punkpeye opened this issue Dec 21, 2024 · 0 comments
Open

Graceful z.array() #3922

punkpeye opened this issue Dec 21, 2024 · 0 comments

Comments

@punkpeye
Copy link

In an ideal world, there would be a way to have an option that quietly discards array members that do not match the schema.

const results = z.gracefulArray(
  z.object({
    name: z.literal('foo')
  })
).parse([
  {
    name: 'foo'
  },
  {
    name: 'bar',
  }
]);

console.log(results);

[
  {
    name: 'foo'
  },
]

so it would work almost like a filter

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