zod icon indicating copy to clipboard operation
zod copied to clipboard

Feature Proposal: Allow Support for alternative field names

Open mduesterhoeft opened this issue 5 months ago • 0 comments

What

Extend zod by a possibility to provide alternative or secondary field names. Those secondary field names are considered when parsing an object and the primary field name is not found in an object. This would be a great addition to ease renaming fields in a schema without backward incompatible changes

This could look like this

const schema = z.object({
  myField: z.string().secondaryName('myOldField'),
});

Parsing the following objects would result in the same output

schema.parse({myField:'some'}) // result is {myField:'some'}

schema.parse({myOldField:'some'}) // result is {myField:'some'}

mduesterhoeft avatar Aug 30 '24 14:08 mduesterhoeft