ggascoigneG
tRPC10mo ago
5 replies
ggascoigne

Types question

I'm slowly migrating an old graphql based project over to trpc v11, using @trpc/tanstack-react-query, and rather liking how it all works, but I'm having some difficulties typing some of the code when I try and wrap some of the queries.

I have simple code like this:

export const useGetSettingsQuery = () => {
  const trpc = useTRPC()
  return useQuery(trpc.settings.getSettings.queryOptions())
}


And it works great, but since I have a ton of more complicated apis to migrate, where the variables and the query params change somewhat, I'd like to extract the types for the interface of trpc.<endpoint>.queryOptions. I know how to do this using Parameters<> if trpc were global, but it's not in this pattern, and while I can see that the interface is defined as TRPCQueryOptions<TDef extends ResolverDef>, I basically want to know how I get the type for ResolverDef for my specific endpoint.
Was this page helpful?