Infer useQuery .data type from TRPC

Hello! I am using a lot of joins in my Prisma/TRPC queries, resulting in some pretty chunky union types being returned, see the attached screenshot for an example. As you can see useQuery returns a type with a bit of nesting of a bunch of Prisma types. This works great for intellisence when working directly with listings.data, however, if I want to use that type somewhere else (type def for FC props) I need to create a new type just to use it elsewhere. In the screenshot you can see above I have created a type which is exactly the same as the type being returned by useQuery. This is okay, but pretty hard to maintain, if I change the query to return something else, that type is now invalid Im sure the solution is easy I just cant figure it out. Something like inferredType = typeof listings.data... something like that?
No description
1 Reply
cje
cje15mo ago
Inferring Types | tRPC
It is often useful to access the types of your API within your clients. For this purpose, you are able to infer the types contained in your AppRouter.
Want results from more Discord servers?
Add your server