Skip to content

Commit 28557ed

Browse files
authored
🤖 Merge PR #69660 [@types/express-serve-static-core] 🏷️ Add Promise<void> to RequestHandler's return type by @NatoBoram
1 parent 60fa1f7 commit 28557ed

17 files changed

Lines changed: 33 additions & 26 deletions

File tree

types/architect__functions/test/http-tests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import express = require("express");
2222

2323
const app = express();
2424

25-
app.get("/", (req, res) => res.send("Hello World!"));
26-
app.get("/cool", (req, res) => res.send("very cool"));
25+
app.get("/", (req, res) => void res.send("Hello World!"));
26+
app.get("/cool", (req, res) => void res.send("very cool"));
2727

2828
////////////////////
2929
// tests for arc.http.helpers: https://github.com/architect/functions/blob/master/src/http/index.js#L21-L26

types/create-test-server/create-test-server-tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const server = createTestServer().then((server) => {
1919
});
2020

2121
// You can return a body directly too
22-
server.get("/foo", () => "bar");
22+
server.get("/foo", () => void "bar");
2323
server.get("/foo", "bar");
2424

2525
return server;

types/express-brute-memcached/express-brute-memcached-tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var bruteforce = new ExpressBrute(store);
88

99
app.post(
1010
"/auth",
11-
bruteforce.prevent, // error 403 if we hit this route too often
11+
(req, res, next) => void bruteforce.prevent(req, res, next), // error 403 if we hit this route too often
1212
function(req, res, next) {
1313
res.send("Success!");
1414
},

types/express-brute-mongo/express-brute-mongo-tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ const store = new MongoStore(ready => {
1818
const app = express();
1919
const bruteforce = new ExpressBrute(store);
2020

21-
app.post("/auth", bruteforce.prevent, (req, res, next) => {
21+
app.post("/auth", (req, res, next) => void bruteforce.prevent(req, res, next), (req, res, next) => {
2222
res.send("Success!");
2323
});

types/express-brute/express-brute-tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ store.reset("key", (error: any) => {});
99

1010
var app = express();
1111
var bruteforce = new ExpressBrute(store);
12-
app.post("/auth", bruteforce.prevent, (req, res, next) => {
12+
app.post("/auth", (res, req, next) => void bruteforce.prevent(res, req, next), (req, res, next) => {
1313
res.send("Success!");
1414
});
1515

types/express-oauth-server/express-oauth-server-tests.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,19 @@ resultingAuthorizationCodeMiddleware = expressOAuthServer.authorize();
7272

7373
const expressApp = express();
7474

75+
const authenticatePath = expressOAuthServer.authenticate();
7576
expressApp.all(
7677
"/path",
77-
expressOAuthServer.authenticate(),
78+
(res, req, next) => void authenticatePath(res, req, next),
7879
(req: express.Request, res: express.Response, next: express.NextFunction) => {
7980
res.json({ message: "Secure data" });
8081
},
8182
);
8283

84+
const authenticateProfile = expressOAuthServer.authenticate({ scope: "profile" });
8385
expressApp.get(
8486
"/profile",
85-
expressOAuthServer.authenticate({ scope: "profile" }),
87+
(res, req, next) => void authenticateProfile(res, req, next),
8688
(
8789
req: express.Request & { user?: OAuth2Server.Token | undefined },
8890
res: express.Response,

types/express-serve-static-core/express-serve-static-core-tests.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,8 @@ app.get("/:readonly", req => {
323323
// @ts-expect-error
324324
req.xhr = true;
325325
});
326+
327+
// Starting with Express 5, route handlers and middleware that return a
328+
// `Promise` will call `next(value)` automatically when they reject or throw an
329+
// error.
330+
app.get("/async", Promise.resolve);

types/express-serve-static-core/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export interface RequestHandler<
6161
req: Request<P, ResBody, ReqBody, ReqQuery, LocalsObj>,
6262
res: Response<ResBody, LocalsObj>,
6363
next: NextFunction,
64-
): void;
64+
): void | Promise<void>;
6565
}
6666

6767
export type ErrorRequestHandler<
@@ -75,7 +75,7 @@ export type ErrorRequestHandler<
7575
req: Request<P, ResBody, ReqBody, ReqQuery, LocalsObj>,
7676
res: Response<ResBody, LocalsObj>,
7777
next: NextFunction,
78-
) => void;
78+
) => void | Promise<void>;
7979

8080
export type PathParams = string | RegExp | Array<string | RegExp>;
8181

types/express-ua-middleware/express-ua-middleware-tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import express = require("express");
33

44
const server = express();
55

6-
server.use(userAgent);
6+
server.use(userAgent());
77
server.get("/", (req, res) => {
88
req.userAgent; // $ExpectType UserAgent & UserAgentRaw
99
});

types/feathersjs__express/feathersjs__express-tests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import feathersExpress, * as express from "@feathersjs/express";
2-
import feathers, { Application } from "@feathersjs/feathers";
2+
import feathers from "@feathersjs/feathers";
33

44
const app = feathersExpress(feathers());
55

@@ -13,7 +13,7 @@ const feathersServiceDummy = {
1313
};
1414
const expressMiddlewareDummy = (req: express.Request, res: express.Response, next: express.NextFunction) => {
1515
next();
16-
return app;
16+
app;
1717
};
1818

1919
app.use(express.json());

0 commit comments

Comments
 (0)