ianI
Convex Community10mo ago
2 replies
ian

Zod with TypeScript for Server-side Vali...

In the latest convex-helpers you can now use the zod helpers to specify a returns on zCustom* functions that will also do Convex validation, and thereby generate types when you generate the API.

You can now generate Convex validators from zod validators both to generate a Convex validator that matches the input to the zod validator, as well as one that matches the output of the zod validator. The former is useful for generating a Convex schema if you run zod validation after reading from the database, the latter is useful for generating a Convex schema based on a Zod validator that you run before you insert into the database. I updated the Stack post to match.
Use Zod with TypeScript for argument validation on your server functions allows you to both protect against invalid data, and define TypeScript types ...
Zod with TypeScript for Server-side Validation and End-to-End Types
Was this page helpful?