createCaller(...) & createHydrationHelpers<...>(...) clash. What is going on?
I've searched and was surprised to find this issue was not addressed anywhere else in this discord.
In the
trpc/server.ts
file generated by CT3A, there seems to be a type mismatch between the return value of createCaller(createContext)
and createHydrationHelpers
in lines 24–30. Specifically, I'm encountering the following TypeScript error:
Has anyone else encountered this issue, or could someone shed light on what might be causing this clash?3 Replies
Solved. For others who are experiencing the same issue, this happens if you do not provide any TRPC routers in
server/api/root.ts
appRouter.Specifically, AppRouter is ensuring that
createHydrationHelpers
and whatever else had the correct type context for the router. If no tRPC routes are defined, createHydrationHelpers
will fail because it relies on a valid AppRouter that represends atleast one populated tRPC router in the application
Otherwise, the inferred type defaults to an empty object and causes type errors
For edge cases like mine, I think it would be good to have some sort of fallback mechanism that dynamically ensures the router has at least one default route if none are provided, i'll try to submit a pull request later for this