The inferred type of this node exceeds the maximum length the compiler will serialize.
Hey, there I am running into this error when I have more than 12 routers in the mergeRouters function.
The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.
version: latest
related: https://github.com/trpc/trpc/issues/2568 // that din't work for me.GitHub
[v10] bug: TypeScript not willing to serialize the type of my clien...
Provide environment information System: OS: macOS 12.5 CPU: (10) arm64 Apple M1 Pro Memory: 152.64 MB / 32.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.16.0 - ~/.nvm/versions/node/v16.16.0/bin/...
13 Replies
Are you able to share your code?
it's a private repo, I can share snippet if you like to.
I am referring to cal.com setup, my local setup for cal.com also error out the same way.
https://github.com/calcom/cal.com/blob/main/packages/trpc/server/routers/viewer.tsx#LL1281C20-L1281C20,
uncommenting any of the last three gives that type error on appRouter
Interesting
I think it's worth opening a fresh issue for this, but it would be very helpful to have a reproduction repo
Oh and I forgot to mention,
it works when I set
declaration: false
in tsconfig.json
.
I dont know, if that's okay or will have cons for itJust to be sure, do you have strict:true enabled?
That can help a lot of perf things
yup, it's set to true
Great
I'd open a GitHub issue then
sure, thanks.
in the past we have recommended turning off that option if you dont need it
https://www.typescriptlang.org/tsconfig#declaration
tldr; it generate a d.ts file for every file. which is unnecessary in most cases
Just for my own sanity, why are you merging 2 un-namespaced routers with the second one an already merged set of namespaced routers?
just so that I get to question right
Did you mean I could do this instead ?
I followed this setup,
https://github.com/calcom/cal.com/blob/main/packages/trpc/server/routers/viewer.tsx#LL1281C20-L1281C20,
Also, thanks you made me realize
router()
is Deprecated
https://trpc.io/docs/typedoc/server/functions/router-1#deprecatedYes that’s what i meant…or use router({…}) for namespaced endpoints. I’ve never seen the two mixed so I’m curious
https://trpc.io/docs/server/merging-routers#merging-with-tmergerouters
Merging Routers | tRPC
Writing all API-code in your code in the same file is not a great idea. It's easy to merge routers with other routers.
I moved everything into
router({ })
, and the type error is gone.
Just a head ups @Nick Lucas, it's fixed for me now. I hadn't created a github issue, as I couldn't reproduce the issue easily.
thanks a lot all of you.