Help with `convexToZod` and spreading fields
I've been trying to get this (and variations of it) to work but I can't figure it out
What's the right way to do this?
11 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!
So i have gone about this with a different approach - zod first rather than validator first? I'm curious who else is here.
I have even more incentive to do this across my whole project because of the agent component use of zod.
I'm currently doing
then i can make use of extends and omit and covert to convex validators if needed.
I'm very close to just redoing 100+ validators and infer types from zod instead of convex. Its a huge undertaking. But i think will pay off
yeah this is my overall approach as well, just struggling with this case where I have
authTables.users.validator
from Convex authAh yeah, i dont use auth but shouldn't this work
Yeah i think i ran into that already also 🙃 . I guess the question is what is the trick..
Hoping Ian can chip in tomorrow
claude 4 says do
I believe your code ends up looking like:
whereas I suspect you want
which would be
Cool!!! That fixes it! Now having another issue though. When I have the following:
For some reason, any query that returns a user document, e.g.
returns a
GenericDocument
type. Any ideas on what's going on/what I'm doing wrong?
The above should hopefully be easy to repro for you 🙏 lmk if you observe the sameConfirming:
getAuthUserId
has return type Id<"users">
that you observe on userId
?
I'd debug by doing things like
or whether this works:
etc.
At some point the schema is either not able to get the type of userId
or the DataModel doesn't have data on the user table.