cha0sg0d
cha0sg0d6mo ago

How to get the type of context after middleware context extension?

I have a middleware where I validate and set a userId. My router knows that userId is no longer undefined, but I need to pass the route context to another function. How do I set the input type for that function such that userId is no longer undefined?
4 Replies
NeoBean
NeoBean6mo ago
I have the same question.
Nick
Nick6mo ago
Any reason that function needs coupling to your context types at all? It may seem like the lazy and easy way, but it’s usually best to define your interfaces properly Service classes etc shouldn’t be aware of tRPC
NeoBean
NeoBean6mo ago
I dont see a valid reason or requirement. but the lazy way may sometime feel intuitive to tell myself this function belongs strictly to these contexts. I agree with you 👍
Nick
Nick6mo ago
Yeah, the way I would do it if I wanted lazy, would be to break apart my context types into somewhere central, build my context types from there, and then at least have that stuff consumable/composable for service classes but for userId:string I suspect you don't need a UserId type exported from anywhere 😛
More Posts
what am i doing wrong?My turbo repo containing expo-clerk-trpc does NOT work. and I've tried everything I have no idea whaReusable Component to take router as props / dependency injection. How to type?for example: ```ts export const Content = async ({ api }) => { const items = await api.getAll.quertRPC mutate call firing two requests with custom linkNode: 18.16 tRPC: 10.38.0 pnpm What's wrong with this custom link that's causing it's addition to aIssue with Fastify / tRPC / AngularWe are trying to setup Angular project with tRPC. In Angular we get following error: ``` Error: nodDrizzle query not working only inside trpcMy drizzle query works inside a regular nextjs api route. The same query running inside trpc throws Server freezes when doing mutations...I have the exact same issue as mentioned in this post: https://discord-questions.trpc.io/m/117697170Create Wrapper only for Procedures that support Infinite QueryGreetings, I'm attempting to create a help that will handle some generic logic I desire for a seriWhy am I getting 'Argument type is not assignable to parameter type ProcedureResolver<unknown>'?I have this warning in my editor (jetbrains InteliJ): ``` Argument type () => any[] is not assignabEfficient way to use tRPC client with auth headers from secure storageWondering if anyone has a recommended pattern on caching the deviceId / authHeader using a React ConUsing tRPC with Expo API Routes feature?Is there a possibility to merge "tRPC Express Adapter" with "Expo API Route Express Deployment"? tR