How to assign types created with convex/values to function parameters?
I want to create a utility function but need to pass an argument that has type safety.
How can I reuse the type from a
convex/values
into a normal function?
Example
schema.ts
Here I have my utility function. I can use some hacks around it but the compiler won't know when the cut
definition changed.
utils.ts
6 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!
Schemas | Convex Developer Hub
Schema validation keeps your Convex data neat and tidy. It also gives you end-to-end TypeScript type safety!
Argument and Return Value Validation | Convex Developer Hub
Argument and return value validators ensure that
ah yeah, that looks like it will help. Thanks!
Yet another link saying the same stuff -- https://docs.convex.dev/production/best-practices/typescript#inferring-types-from-validators
thank you
works like a charm