You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I have some defined schema and I want to change only the property value from it to be validated on PARSE, it not work as expected.
Inside application, the type infers correctly, like my object.ids, can access the possible object with the new property name, but on PARSE, seems to not recognize the renamed property it expects to the last one, e.g., disabled_group.
I have another schema with the same shape, just need to change the property name validation, so I tried with transform, maybe I missunderstood the usage of it.
Make a new schema with ids name, works fine! So I'm following this way at the time
e.g.:
// zod helperimport{ZodEffects,ZodType}from'zod';exportnamespaceZodHelpers{exportfunctionnonemptyObjects<TextendsZodType>(zodBaseObject: T): ZodEffects<T>{returnzodBaseObject.refine((schema)=>Object.keys(schema).length>0,'JSON cannot be empty');}}// some dto schemaexportconstBulkDisableQuerySchema=ZodHelpers.nonemptyObjects(z.object({disabled_group: z.array(z.number()).nonempty().optional(),}).strict(),);// ❌ NOT WORK -> keep expecting for disable_group// transformed schema with new property name, but shape and everything sameexportconstBulkDeleteQuerySchema=BulkDisableQuerySchema.transform((property)=>({ids: property.disabled_group})// ✅ WORK as expected, but it's the same shapeexportconstBulkDisableQuerySchema=ZodHelpers.nonemptyObjects(z.object({ids: z.array(z.number()).nonempty().optional(),}).strict(),);
Possible problem:
When I have some defined schema and I want to change only the property value from it to be validated on PARSE, it not work as expected.
Inside application, the type infers correctly, like my
object.ids
, can access the possible object with the new property name, but on PARSE, seems to not recognize the renamed property it expects to the last one, e.g.,disabled_group
.I have another schema with the same shape, just need to change the property name validation, so I tried with transform, maybe I missunderstood the usage of it.
Make a new schema with ids name, works fine! So I'm following this way at the time
e.g.:
Error
Expected
ids
.Version:
The text was updated successfully, but these errors were encountered: