v2.4.0
What's Changed
New Features 🎉
-
Enhance ZodLazy support by @samchungy in #102
This should allow you to write recursive ZodSchema like this:
const BasePost = z.object({ id: z.string(), userId: z.string(), }); type Post = z.infer<typeof BasePost> & { user?: User; }; const BaseUser = z.object({ id: z.string(), }); type User = z.infer<typeof BaseUser> & { posts?: Post[]; }; const PostSchema: ZodType<Post> = BasePost.extend({ user: z.lazy(() => UserSchema).optional(), }).openapi({ ref: 'post' }); const UserSchema: ZodType<User> = BaseUser.extend({ posts: z.array(z.lazy(() => PostSchema)).optional(), }).openapi({ ref: 'user' });
Other Changes
-
Fix type exports by @samchungy in #106
This change fixes an issue introduced in v2.3.1 and should resolve the following Typescript compilation error for any versions < 5.0.
TS1383: Only named exports may use 'export type'.
Please note: there may be a breaking change in the future to require Typescript 5.0.
Full Changelog: v2.3.3...v2.4.0