glucinater
glucinater12mo ago

Using Convex Validators in Typescript

Is there a way to use Convex Validators to validate ts objects? I've attached an example of the functionality from Zod I would like Convex to replace
No description
4 Replies
ian
ian12mo ago
You can currently only use convex validators on function arguments (query/mutation/action) and database schema. However I wrote some helpers to turn a zod validator into a convex validator for use as arguments / schema if you want to keep the definition in zod
ian
ian12mo ago
Using Zod with TypeScript for Server-side Validation and End-to-End...
Use Zod with TypeScript for argument validation on your server functions allows you to both protect against invalid data, and define TypeScript types ...
glucinater
glucinaterOP12mo ago
Gotcha, that’s what I’m currently doing. Just curious if there was a way to do what I did above using only the schema since it’s for a Doc type in my db
ian
ian12mo ago
Yeah I think it'd be great to provide a runtime validator you can call. On the backlog

Did you find this page helpful?