Jacob
Jacob3mo ago

Losing type-safety with merged routers

When using router exported from an external file, I lose any sort of type safety for the procedures on in that router. router.ts
export const appRouter = router({
users: usersRouter,
test: {
create: procedure.input(z.string()).query(({ input }) => {
return 'Hi ' + input;
}),
list: procedure.input(z.string()).query(({ input }) => {
return 'Hi ' + input;
})
}
})
export const appRouter = router({
users: usersRouter,
test: {
create: procedure.input(z.string()).query(({ input }) => {
return 'Hi ' + input;
}),
list: procedure.input(z.string()).query(({ input }) => {
return 'Hi ' + input;
})
}
})
users.ts
export const usersRouter = router({
create: procedure.input(z.string()).query(({ input }) => {
return 'Hi ' + input;
}),
list: procedure.input(z.string()).query(({ input }) => {
return 'Hi ' + input;
})
});
export const usersRouter = router({
create: procedure.input(z.string()).query(({ input }) => {
return 'Hi ' + input;
}),
list: procedure.input(z.string()).query(({ input }) => {
return 'Hi ' + input;
})
});
On my frontend I call the trpc object api api.test is typed as expected, api.users however is any. I can quite figure out what I'm doing wrong 🤔
3 Replies
Mika
Mika3mo ago
I know this sounds dumb but try reloading/restarting vscode if you haven't already. more often than not whenever I see any my reflex is to reload vscode
Jacob
Jacob3mo ago
I tried this thinking that was the issue but unfortunately it remains
infodusha
infodusha2mo ago
That probably could also be a result of circular imports? Check if users.ts imports something from router.ts.