Ole Asteo
Ole Asteo5d ago

Re: relative imports to trpc.ts

For reference: https://github.com/trpc/trpc/pull/6112 @Nick Lucas Let's assume for a second it were the case that it's something wrong with the setup. How comes the type inference of type AppRouter = typeof appRouter on the server side works as expected, regardless of relative / path alias import. But only upon client side import, the type isn't inferred properly anymore? Is there any known project that uses different packages and path alias imports and still works that you could guide me to?
GitHub
docs(server/routers): add warning to use relative imports to trpc.t...
✅ Checklist I have followed the steps listed in the Contributing guide. If necessary, I have added documentation related to the changes made. I have added or updated the tests related to the ch...
Solution:
I finally discovered the root cause. It's a typescript issue. By implication you can call this a setup issue. I stay humbled @Nick Lucas 🙏 Basically, using tsconfig paths within the child packages in monorepos is a bad idea :/ The server/user.router.ts will use the client/tsconfig.json#paths for module resolution during the import from client/index.ts (in contrast to imports from within server/)....
Jump to solution
2 Replies
Ole Asteo
Ole Asteo5d ago
PS: Sorry for being all over the place. #❓-help does not show up in forwarding dialogs as it's not a text channel ^^ @julius is going to look into this. I don't think we need to multiple people look into this at once. So, I say we wait for his investigation first. Hit me up if I need to clarify anything further, but I think you understand the issue 🙂
Solution
Ole Asteo
Ole Asteo5d ago
I finally discovered the root cause. It's a typescript issue. By implication you can call this a setup issue. I stay humbled @Nick Lucas 🙏 Basically, using tsconfig paths within the child packages in monorepos is a bad idea :/ The server/user.router.ts will use the client/tsconfig.json#paths for module resolution during the import from client/index.ts (in contrast to imports from within server/). So, having a single @/ alias for the src/ dir of the current package seems impossible (unless you risk a merged type alias). I'll update the PR and improve the description in FAQ/Troubleshooting. Sorry for the tumult.