Passing generic inside tRPC query
Hi, I hope you're doing well.
Server:
Nextjs front:
I would like to pass the type of my Prisma query (
{ include: { image: true } }
) to findManyUser, so users
has the expected type and not the default type provided by Prisma (without generics : DefaultArgs
).
Thanks for your help.
Have a great day/night!3 Replies
Any help would be greatly appreciated. This is an issue I’ve encountered numerous difficulties and questions about on various forums, but I haven’t found a solution (or perhaps I’ve misunderstood some of the discussions) 🤍
Hey, I’m not familiar with trpc but I do with react query.
In your front, provide the types for the useQuery generics.
If im not mistaken it receives 4 different types.
Payload Type
Error Type
Response Type
Another type I always forgets
Should be something like
useQuery<TPayload, unknown, TResponse>
Hi, in tRPC, when using useQuery<...>, it works similarly to type casting. However, I can't deduce the Payload Type from the Response Type.
So, to use it, I need to know the response type of the queryProcedure in advance.
Thanks a lot for your answer, by the way! 🌟
it seems to be unfeasible: https://github.com/trpc/trpc/discussions/2150. If anyone has an idea on how to properly use the cast with useQuery, feel free to share 👍