TanStackT
TanStack8mo ago
8 replies
rubber-blue

Type errors chaining middleware together.

In the docs, it suggests you can chain middleware together while building up state in context. But in this case, the context is not typed unlike the majority of Start because the middleware can be used in different spots.

Maybe we should add an explicit typing for the context that each middleware supports?

Something like createMiddleware().context( z.object( { authUser: AuthUser.optional() } ).passthrough() ).validator(.....).server(...)

So that one can put in compile time guarantees on the context required. I believe it would get rid of the type errors in the middleware functions and also validate you combined multiple middlewares correctly in a server function. Bomb.

FYI: I'm using TanStack/Start+Router v1.120.13.
Screenshot_2025-06-03_at_9.44.06_AM.png
Screenshot_2025-06-03_at_9.47.53_AM.png
Was this page helpful?