end to end typing
Does convex support generating types for input / output of the cloud function that can be directly plugged in react/typescript?
7 Replies
Yes the types from your functions are automatically available from the react client
Alex wrote a post about how we do this I can share, but short answer yes
Hey Ian, mind sharing the article? I didn't find any examples in the convex-demo repo and you may consider adding one, thanks
Here you go- hasn’t been publicly published but https://stack.convex.dev/end-to-end-ts
End-to-end TypeScript with Convex
Convex provides automatic type safety all the way from your database schema to your React app. How does it work? Hint: we use some wild TypeScript.
The basics though is that it works by default, are they not working for you already? You don’t have to set anything up
How do I get the explicit type of the returns? In my case
If tools is a table, you can use Doc<“tools”>. There’s actually some other nifty things called out in some docs on typescript types. The return type is also pretty easy but I’m afk so I’ll have to follow up later. You can click into useQuery and there’s probably something in there that you can use for inspiration
Hey Ian I believe the return type can probably be retrieved via
ReturnType<NamedQuery<API, Name>>
but I don't see NamedQuery being exported