tRPCttRPC
Powered by
gklineG
tRPC•2y ago•
1 reply
gkline

Union context type to allow incremental upgrade to App router

Hi there. We have a tRPC API that is currently being served from the NextJS Pages router. We're looking to migrate to the App router, and in the process I am being tasked with finding a way to reuse all of our existing routers/routes.

I have the new app-router-router setup and serving requests, and now I'm trying to find a way to hook up to our existing routes. The issue is, the two context objects seem to be incompatible. One has the Pages router Req and Res properties, while the other just has the Req property. Otherwise, the types are exactly the same. I have handling so that all of our middleware works with either context type, yet defining base procedures results in a type error.

Is there any way I can rectify this, so that for example, our teamProcedure would work on two different types of context? I've managed to figure everything else out, except for this. Thanks!

App specs:
Node v20.15
tRPC v10.45
Next v14.2
CleanShot_2024-07-16_at_08.13.042x.png
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

Migrating pages router to app router
spreen_coSspreen_co / ❓-help
11mo ago
Vitest context router caller
MugetsuMMugetsu / ❓-help
3y ago
Incomplete imported router type
Mr. JokerMMr. Joker / ❓-help
10mo ago
How to infer type of a nested object from app router output?
boneyBboney / ❓-help
3y ago