The inferred type of this node exceeds the maximum length the compiler will serialize.

HHussam3/30/2023
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.
Nnlucas3/30/2023
Are you able to share your code?
HHussam3/30/2023
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,
HHussam3/30/2023
export const appRouter = mergeRouters(
    router12,
    router({
        router1, 
        router2,
        router3,
        router4,
        router5,
        router6,
        router7,
        router8,
        router9
        router10,
        router11,
        // router13,
        // router14,
        // router15,
    }),
);

uncommenting any of the last three gives that type error on appRouter
Nnlucas3/30/2023
Interesting
Nnlucas3/30/2023
I think it's worth opening a fresh issue for this, but it would be very helpful to have a reproduction repo
HHussam3/30/2023
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 it
Nnlucas3/30/2023
Just to be sure, do you have strict:true enabled?
Nnlucas3/30/2023
That can help a lot of perf things
HHussam3/30/2023
yup, it's set to true
Nnlucas3/30/2023
Great
Nnlucas3/30/2023
I'd open a GitHub issue then
HHussam3/30/2023
sure, thanks.
Ttrash_dev3/30/2023
in the past we have recommended turning off that option if you dont need it

https://www.typescriptlang.org/tsconfig#declaration
Ttrash_dev3/30/2023
tldr; it generate a d.ts file for every file. which is unnecessary in most cases
Mmsalsbery3/31/2023
Just for my own sanity, why are you merging 2 un-namespaced routers with the second one an already merged set of namespaced routers?
HHussam3/31/2023
just so that I get to question right
Did you mean I could do this instead ?

export const appRouter = mergeRouters(
        router12,
        router1, 
        router2,
        router3,
      ......
);


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#deprecated
Mmsalsbery3/31/2023
Yes 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
HHussam3/31/2023
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.