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
4 Replies
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
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 ...
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
Yeah I think it'd be great to provide a runtime validator you can call. On the backlog