Zod 4 Beta Announced! (Performance, Bundle Size, JSON Schema, Recursion)

Share

Summary

An overview of the new features and improvements in Zod 4 beta, including performance enhancements, reduced bundle size, JSON schema conversion, and recursive type support.

Highlights

Introduction and Performance Improvements
00:00:00

Zod 4 beta is announced with significant performance improvements over Zod 3, including faster string, array, and object parsing. TypeScript performance is also vastly improved, reducing type instantiations in large codebases.

Bundle Size Reduction and Zod Mini
00:01:28

Zod 4 features a smaller bundle size. Zod Mini, a new tree-shakable sister library, further reduces bundle size, making Zod more suitable for front-end environments. It uses wrapper functions instead of methods for better tree-shaking.

JSON Schema Conversion
00:03:17

Zod 4 introduces first-class JSON schema conversion, which is useful for AI applications involving structured outputs and tool calling. The z.toJSJSONSchema function allows to creating a JSON schema from Zod schemas.

Schema Registry and Metadata
00:04:07

Zod 4 implements new system `meta` for adding strongly typed metadata to schemas, stored in a schema registry decoupled from the schemas themselves. `describe` still works but it's not recommended anymore.

Z.inface for Object Types / Recursive Types
00:04:46

Z.inface API to define object types with exact optional properties and recursive types. Solves the problem of representing key optional and value optional properties, and simplifies recursive type definitions without nasty maneuvers.

File Validation
00:07:37

Zod now validates file instances using Z.File with checks for minimum size, maximum size, and MIME type, which improves handling form data file uploads.

Error messaging and String formats
00:07:52

Zod introduces a local API for translating error messages into different languages. Zod now implements a top-level z.pritifyError function so you get a really gorgeous pretty printable multi-line string. All string formats like email and IPs etc. are moved to the top level of the module.

Template Literal Types and String Booleans
00:09:16

Zod 4 brings Z.lateLiteral to convert one to one from Zod into Typescript template literal types. Z.stringBool converts strings to booleans with customizable truthy/falsy values, which is useful for query parameters.

Closing Remarks
00:10:29

The presenter expresses excitement about the new features in Zod 4 and mentions needing to update their Zod tutorial. The presenter promotes his AI course.

Recently Summarized Articles

Loading...