tRPCttRPC
Powered by
jacobJ
tRPC•2y ago•
4 replies
jacob

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
api.test
is typed as expected,
api.users
api.users
however is
any
any
.

I can quite figure out what I'm doing wrong 🤔
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

type safety with meta
BeanBBean / ❓-help
2y ago
Type safety with enabled option
alexAalex / ❓-help
4y ago
How does routing work in tRPC especially when using merged routers?
rockchalkwushockRrockchalkwushock / ❓-help
3y ago