Convex type to Zod type?
Is there a way to go from a convex type to a zod type?
Specifically want to do this for defining tool calls for vercel ai sdk so it can directly call the args of an action/mutation (obv I have some validation for security)
4 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
https://www.npmjs.com/package/tozod might be a helpful way to type enforce creating a compatible zod type, but it still requires writing the type twice
There's a helper for this: https://github.com/get-convex/convex-helpers/blob/main/packages/convex-helpers/README.md#zod-validation
GitHub
convex-helpers/packages/convex-helpers/README.md at main · get-con...
A collection of useful code to complement the official packages. - get-convex/convex-helpers
That’s a little bit the other way, but I found that we can just lean on the type inference between zod and convex to work in most cases anyway 🙂