Create Wrapper only for Procedures that support Infinite Query
Greetings,
I'm attempting to create a help that will handle some generic logic I desire for a series of infinite queries. I found this stackoverflow post, https://stackoverflow.com/questions/77096846/wrap-usequery-of-trpc-in-a-custom-hook-with-correct-typescript-types, which is essentially what I want. The only difference is that I only want to accept procedures that implement the inputs required for the useInifiniteQuery method to be available. The implementation above will not expose that function.
I noticed that the main difference is that the inputs params for an infinite query procedure must have { cursor?: any }. There's no built in Procedure for infiniteQuery, but I thought I could make one by doing something like this.
type InfiniteQueryProcedure = Procedure<"query", any & { cursor?: any }>;
I think this is saying, this is a query and the input params support a cursor. However, when I pass this Procedure type to the DecorateProcedure, it does not seem to recognize the types correctly to enable the useInfiniteQuery method.
Stack:
- node v20
- pnpm
- TRPC v10
Stack Overflow
Wrap useQuery of tRPC in a custom hook with correct TypeScript types
I'm using tRPC in a project with already existing API calls and would like to wrap the useQuery function into a separate wrapper, but I'm struggling with getting the TypeScript types right.
What I ...
0 Replies