Returns Validation Error
I added some return validators to my convex queries. I get typescript errors if I don't return all the fields, however there are no typescript errors if I return extra fields.
From what I understand, this is not possible in typescript??
However, the problem is I get a runtime error "ReturnsValidationError: Object contains extra field..."
What is the recommended approach here? Can I either turn off this client side validation error, as I don't really care if there are extra fields, so long as the expected fields are there.
Or is there some sort of parse/validation built in to the convex/values library to ensure that the validation requiremenets are met at build time not runtime?
2 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!
Yes, unfortunately this isn't possible in TypeScript.
Runtime validation is safer because it actually enforces there are no extra properties, but if it's a good fit for your application (e.g. you don't have private data, or you aren't worried about new fields of documents in your database inadvertently being returned) so you only want TypeScript errors you can use a TypeScript return annotation:
