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?
Screenshot_2023-09-16_at_7.44.53_pm.png
Was this page helpful?