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:
Argument of type 'DecorateRouterRecord<{}>' is not assignable to parameter of type 'TypeError<"Generic parameter missing in `createHydrationHelpers<HERE>`">'.

Type 'DecorateRouterRecord<{}>' is not assignable to type '"Generic parameter missing in `createHydrationHelpers<HERE>`"'
Argument of type 'DecorateRouterRecord<{}>' is not assignable to parameter of type 'TypeError<"Generic parameter missing in `createHydrationHelpers<HERE>`">'.

Type 'DecorateRouterRecord<{}>' is not assignable to type '"Generic parameter missing in `createHydrationHelpers<HERE>`"'
Has anyone else encountered this issue, or could someone shed light on what might be causing this clash?
No description
3 Replies
tmp.st
tmp.stOP4w ago
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.
tmp.st
tmp.stOP4w ago
No description
tmp.st
tmp.stOP4w ago
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
Want results from more Discord servers?
Add your server