Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,6 @@ app.router.stack;
app.on("mount", (app) => {
app; // $ExpectType Application<Record<string,any>
});

// QUERY method presence depends on environment
app.query?.("/foo/bar", (req) => req.method);
7 changes: 6 additions & 1 deletion types/express-serve-static-core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type ParseRouteParameters<Route extends string> = string extends Route ? ParamsD
/* eslint-disable @definitelytyped/no-unnecessary-generics */
export interface IRouterMatcher<
T,
Method extends "all" | "get" | "post" | "put" | "delete" | "patch" | "options" | "head" = any,
Method extends "all" | "get" | "post" | "put" | "delete" | "patch" | "options" | "head" | "query" = any,
> {
<
Route extends string | RegExp,
Expand Down Expand Up @@ -268,6 +268,11 @@ export interface IRouter extends RequestHandler {
patch: IRouterMatcher<this, "patch">;
options: IRouterMatcher<this, "options">;
head: IRouterMatcher<this, "head">;
/**
* Requires Node.js >=20.19.3 <21 || >=22.2.0
* @see https://expressjs.com/en/5x/api/application/#appquery
*/
query?: IRouterMatcher<this, "query">;

checkout: IRouterMatcher<this>;
connect: IRouterMatcher<this>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,6 @@ app.get("/:readonly", req => {
// @ts-expect-error
req.xhr = true;
});

// QUERY method presence depends on environment
app.query?.("/foo/bar", (req) => req.method);
7 changes: 6 additions & 1 deletion types/express-serve-static-core/v4/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export type RouteParameters<Route extends string> = string extends Route ? Param
/* eslint-disable @definitelytyped/no-unnecessary-generics */
export interface IRouterMatcher<
T,
Method extends "all" | "get" | "post" | "put" | "delete" | "patch" | "options" | "head" = any,
Method extends "all" | "get" | "post" | "put" | "delete" | "patch" | "options" | "head" | "query" = any,
> {
<
Route extends string,
Expand Down Expand Up @@ -261,6 +261,11 @@ export interface IRouter extends RequestHandler {
patch: IRouterMatcher<this, "patch">;
options: IRouterMatcher<this, "options">;
head: IRouterMatcher<this, "head">;
/**
* Requires Node.js >=20.19.3 <21 || >=22.2.0
* @see https://expressjs.com/en/4x/api/application/#appquery
*/
query?: IRouterMatcher<this, "query">;

checkout: IRouterMatcher<this>;
connect: IRouterMatcher<this>;
Expand Down
3 changes: 3 additions & 0 deletions types/express/express-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ namespace express_tests {
router.put(path);
router.post(path);
router.delete(path);
router.query?.(path);
router.get(pathStr);
router.put(pathStr);
router.post(pathStr);
router.delete(pathStr);
router.query?.(pathStr);
router.get(pathRE);
router.put(pathRE);
router.post(pathRE);
router.delete(pathRE);
router.query?.(pathRE);

router.use((req, res, next) => {
next();
Expand Down
3 changes: 3 additions & 0 deletions types/express/v4/express-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ namespace express_tests {
router.put(path);
router.post(path);
router.delete(path);
router.query?.(path);
router.get(pathStr);
router.put(pathStr);
router.post(pathStr);
router.delete(pathStr);
router.query?.(pathStr);
router.get(pathRE);
router.put(pathRE);
router.post(pathRE);
router.delete(pathRE);
router.query?.(pathRE);

router.use((req, res, next) => {
next();
Expand Down
Loading