trpc.legacyRouterName.procedure "does not exist" on type CreateTRPCNextBase, runs anyway
Have reached the end of a massive trpc 9 -> trpc 10 migration, executed using the official guide with conventions copied from the tRPC Prisma starter. (big thanks to @alex / KATT and @Nick Lucas for your support on here while I frustratingly hacked on our massive codebase)
When running legacy procedures such as
trpc.tasks.getAllTasks.useQuery(...)
, .tasks
will throw the "does not exist on type CreateTRPCNextBase<Router..."
type error, but will run successfully anyway.
The only procedures I can see are my v10 router's greeting
procedure and router methods such as useContext()
.
Any insight or direction toward solving this issue would be greatly appreciated!
I wonder if this is a result of our legacy middleware?4 Replies
“tasks.”?
Dot!
Still not found
and that breaks the query methods (e.g. tasks.getTasks or w/e)
My router appears to only be getting the typing of
mainRouter
(trpc 10 router with greeting) from appRouter = mergeRouters(legacyRouter, mainRouter);
Since these legacy procedures work (e.g. trpc.tasks.getAll
) but are not reflected in typeof appRouter
, I wonder if this is a type inference bug with mergeRouters
if I do const allTasks = trpc['tasks']['findAll'].useQuery();
for a legacy query I don't get a type error, but that seems like a workaround rather than intended usage
I have a standalone query procedure on the legacy router called "health", this and all my other legacy procedures show up as the following on the CreateTRPCNextBase
type: queries: MigrateProcedureRecord<RootConfig<{ ctx...}; errorShape: DefaultErrorShape; meta: {}; transformer: DefaultDataTransformer; }>, SwapContext<SwapContext<{}, { ...ctx }>, { ...ctx }> & Record<"health", Procedure<{ ...ctx }, { ...ctx }, {}, undefined, undefined, string, unknown, string>>
Definitely PEBCAK still, but it’s quite hard to tell from afar
I’d be doing lots of hovering over types, and trying to trim down the problem space by commenting routers and maybe exporting the tasks factory result directly as the appRouter just to experiment
I’ll meet you halfway on PEBCAK, as it would be helpful to see a working example of a legacy router in tRPC 10’s resources in addition to more detail in the v10 migration guide for those of us with robust v9 implementations.
Thanks for the suggestion
The real answer to this is legacy routers are completely incompatible with CreateTRPCNextBase.