zod icon indicating copy to clipboard operation
zod copied to clipboard

Strip object values that fail member validation

Open osdiab opened this issue 2 years ago • 4 comments

The strip method allows for invalid keys to get stripped, but would love an equivalent for invalid values to help make our site more robust.

I see the suggestions in this similar issue, but the painful part with those is that every key that can possibly be invalid would need to have the transform applied; in a large schema with like 40 members, that's fairly annoying.

I guess one idea is that I can do something like (with a mapValues() helper we have):

const stripBadValuesSchema = z.object(mapValues({
  foo: z.string(),
  bar: z.number()
}, schema => schema.or(z.unknown().transform(() => undefined)));

but wondering if there's a more idiomatic way to do this. Thanks!

osdiab avatar Apr 20 '22 12:04 osdiab

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 19 '22 13:06 stale[bot]

ding dong

osdiab avatar Jun 25 '22 05:06 osdiab

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 30 '22 23:08 stale[bot]

still an issuse

Omar

On Wed, Aug 31, 2022 at 8:24 AM, stale[bot] @.***> wrote:

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

— Reply to this email directly, view it on GitHub https://github.com/colinhacks/zod/issues/1090#issuecomment-1232270558, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAONU3VMLJ7SPTAGIJI3XJTV32J4HANCNFSM5T3535WA . You are receiving this because you authored the thread.Message ID: @.***>

osdiab avatar Aug 31 '22 05:08 osdiab

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 31 '22 08:10 stale[bot]