tRPCttRPC
Powered by
Ole AsteoO
tRPC•2y ago•
4 replies
Ole Asteo

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
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...
docs(server/routers): add warning to use relative imports to trpc.t...
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
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.
Jump to solution
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

Shorten /app/api/trpc/[trpc]/route.ts
functiondjFfunctiondj / ❓-help
6mo ago
Trpc Vanilla client producing ts errors
MaxMMax / ❓-help
4y ago