TypeScript - itty-router updated in v5
Typing with routers, where middleware can naturally affect not only the same handler, but downstream handlers... is hard.
That said, we've tried to make it all easy for you to extend request types, add support for your own properties, environment variables, etc.
We've broken things down into the simple categories of:
Request Types
This just describes the core request types that everything extends throughout the router. Start here.Routes & Routers
Typing routes (and entire routers) using generics.Request handlers & Middleware
Typing... you guessed it, request handlers and middleware arguments.Response Handlers
For all your downstream response-handler needs, as used in thefinally
stage ofAutoRouter
andRouter
.Additional Arguments
For when you need to type anything beyond therequest
in handlers. For example, handling the environment andExecutionContext
in Cloudflare Workers.API
The complete TypeScript API. *bows*