Skip to content

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:

  1. Request Types
    This just describes the core request types that everything extends throughout the router. Start here.

  2. Routes & Routers
    Typing routes (and entire routers) using generics.

  3. Request handlers & Middleware
    Typing... you guessed it, request handlers and middleware arguments.

  4. Response Handlers
    For all your downstream response-handler needs, as used in the finally stage of AutoRouter and Router.

  5. Additional Arguments
    For when you need to type anything beyond the request in handlers. For example, handling the environment and ExecutionContext in Cloudflare Workers.

  6. API
    The complete TypeScript API. *bows*