zod
zod copied to clipboard
feat: `strict` option for transforming overflow properties to value
It would be handy if ZodObject's strict function accepted a parameter that let you transform any overflowing properties to a specific value rather than simplify removing them.
For example:
const user = {
firstName: "foo",
lastName: "bar",
} ;
const filteredUserSchema = z.object({
firstName: z.string(),
}).strict({
castOverflowTo: "[filtered]"
});
// castOverflowTo would result in the parsed return looking like:
// {
// firstName: "foo",
// lastName: "[filtered]"
// }
filteredlUserSchema.safeParse(user).data
This would be very useful for scrubbing data.
Thanks in advance!
Hi, @drakedeatonuk. I'm Dosu, and I'm helping the Zod team manage their backlog. I'm marking this issue as stale.
Issue Summary:
- You proposed enhancing
ZodObjectwith astrictoption to transform overflowing properties to a placeholder value like "[filtered]". - This feature is intended to aid in data scrubbing by replacing unwanted properties.
- You provided an example to illustrate the proposed functionality.
- There has been no activity or comments on the issue since it was opened.
Next Steps:
- Please let us know if this issue is still relevant to the latest version of the Zod repository. You can keep the discussion open by commenting on the issue.
- If there is no further activity, the issue will be automatically closed in 7 days.
Thank you for your understanding and contribution!
This is achievable with .catchall() which accepts an arbitrary schema that will process unrecognized properties.