How to type `request.query` in express using TypeScript?

The solution is to use generics in the following manner.

const router = Router();

interface Foo {
    foo: string;
}

function getHandler(request: Request<{}, {}, {}, Foo>, response: Response) {
  const { query } = request;

  query.foo;

}

router.route("https://stackoverflow.com/")
  .get(getHandler)

Leave a Comment