Closed AlexandreBrayer closed 3 months ago
For more context :
I tried
const UserSchema = z.object({ username: z.string(), email: z.string(), password: z.string(), role: z.enum(['user', 'admin']), createdAt: z.date().optional(), updatedAt: z.date().optional() });
then
const rawSchema = zodSchemaRaw(UserSchema); rawSchema.email.unique = true; rawSchema.username.unique = true;
Property 'unique' does not exist on type '_Field<ZodString> | _Schema<ZodString>'. Property 'unique' does not exist on type '_Field<ZodString>'.ts(2339)
Seems odd, since this code works
nvm i found it const schema = zodSchema(UserSchema);
schema.path('email').unique(true); schema.path('username').unique(true);
Hey Alexandre! Thanks for reaching out.
For right now the only option to add non-zod functionality is to modify the output schema. I'm currently looking into adding some of that similar way to how @samchungy/zod-openapi does.
Anyway, I'll keep this discussion as a feature request for further improvements. Enjoy your day!
@bebrasmell I think this issue is supposed to be closed no?
I wonder how to handle unique fields. Do you have to delcare them after calling the function "zodSchema" ?