How to get the type of a convex function return in react
I am making a typescript app, i want to get the type of the items that the convex function will return, how do i do it?
4 Replies
(typeof api.my.func)['_returnType']
Also i am having difficulites making joints in convex
Here's a post that will help you think through relationships in Convex:
https://stack.convex.dev/relationship-structures-let-s-talk-about-schemas
If you just want to get to code, that post features relationship helper functions from the convex team, and this post focuses on the functional side of using them: https://stack.convex.dev/functional-relationships-helpers
Relationship Structures: Let's Talk About Schemas
In this post we’ll look at some patterns for structuring relationships in the Convex database.
Functional Relationships: Helpers
In this post, we’ll look at some helper functions to help write code to traverse relationships in a readable, predictable, and debuggable way.
If you want a type you've written yourself you could define a type, then annotate the return type of your Convex query/mutation/action.
Inference like
(typeof api.my.func)['_returnType']
is convenient but sometimes you want a reusable type like type User = { ... }
.