tRPCttRPC
Powered by
SpoonmanS
tRPC•15mo ago
Spoonman

Can't get type inference from createTRPCNext instance

Hi everyone,

I have separate FE and BE using tRPC to communicate, in a monorepo environment. The FE app is a simple Next.js app, the BE is tRPC with Express. I'm using Bun as the runtime.

I'm exporting
AppRouter
AppRouter
from the BE as per the instructions, and importing the type in the FE and passing it as a type argument to
createTRPCNext
createTRPCNext
. When inspecting
createTRPCNext
createTRPCNext
in the FE, I can see the type has resolved and the procedures are in there.

However, when I create the FE tRPC instance (
const trpc = createTRPCNext<AppRouter>({...})
const trpc = createTRPCNext<AppRouter>({...})
), the
trpc
trpc
variable has a complex type attached to it (posted below), but nothing is really typed. when I do
trpc.example
trpc.example
(one of my procedures), it's
any
any
. When I try to get the tRPC HOC (
withTRPC
withTRPC
), that is
any
any
also. Why arent the types getting infered properly in the FE? That is what I'm trying to solve at the moment.

The type:

const trpc: ProtectedIntersection<CreateTRPCNextBase<TRouter, TSSRContext>, DecoratedProcedureRecord<TRouter["_def"]["record"], TFlags>>
const trpc: ProtectedIntersection<CreateTRPCNextBase<TRouter, TSSRContext>, DecoratedProcedureRecord<TRouter["_def"]["record"], TFlags>>


Thanks!
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

createTRPCNext type error
MonkeyStructMMonkeyStruct / ❓-help
3y ago
createTRPCNext Type Error + useQuery Not Defined
NickNNick / ❓-help
3y ago
Complex type inference on router outputs?
ianIian / ❓-help
2y ago
Incorrect type inference with discriminated unions.
dechoDdecho / ❓-help
3y ago