fynn
fynn2mo ago

types not working if input provided

Hey guys, just getting into tRPC: If i add a input to a query, in the client, the types are not working anymore. thats normal? is there any way around this?
9 Replies
fynn
fynnOP2mo ago
I am using React Query and the data is just unknown if I add a input to the server query
FluX
FluX2mo ago
Can you share how you've defined the procedure input and how you are calling the query on the client?
fynn
fynnOP2mo ago
you mean this?:
export const notificationRouter = router({
check: publicProcedure
.input(checkNotificationSchema)
.query(({ ctx, input }) => {
....
}),
export const notificationRouter = router({
check: publicProcedure
.input(checkNotificationSchema)
.query(({ ctx, input }) => {
....
}),
here's how I call the query:
const { data } = useQuery(
trpc.notification.check.queryOptions({ path: pathWithoutLocale, context }),
);
const { data } = useQuery(
trpc.notification.check.queryOptions({ path: pathWithoutLocale, context }),
);
just getting into tRPC, so hope thats a good way to do it at all
FluX
FluX2mo ago
Hm yeah that looks correct. Are your trpc client/server versions mismatched maybe?
fynn
fynnOP2mo ago
client:
"@trpc/client": "^11.4.3",
"@trpc/tanstack-react-query": "^11.4.3",
"@trpc/client": "^11.4.3",
"@trpc/tanstack-react-query": "^11.4.3",
server:
"@hono/trpc-server": "^0.4.0",
"@trpc/server": "^11.4.3",
"@hono/trpc-server": "^0.4.0",
"@trpc/server": "^11.4.3",
so yeah, everythings matching. whats weird is that it only cant infer types if I add the .input on the query - without, it works. also on mutations the input is just working fine
FluX
FluX2mo ago
That's weird. In my project I have the exact same setup: Hono, trpc, etc and I don't have this issue. Could it be that the keys path and/or context of your input object cause problems? Or anything else in the input object? That's my only guess ... that is, if only that particular query is affected and other queries work
fynn
fynnOP2mo ago
don't think so, I mean its the same with just a simple zod string. its not particular only this one, every query where I try to use a input has the problem. mutations are working, and queries without an input aswell
FluX
FluX2mo ago
What's your Typescript and tanstack/react-query versions?
fynn
fynnOP2mo ago
typescript 5.8.3, react query 5.83.0 atm

Did you find this page helpful?