From 014195118535669af0ad3bde38a76601dafa4d81 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Tue, 2 May 2023 00:33:33 +0200 Subject: [PATCH] refactor(types): ensure compatibility with Express middlewares In order to prevent issues like: > error TS2345: Argument of type 'RequestHandler>' is not assignable to parameter of type 'Middleware'. > Types of parameters 'req' and 'req' are incompatible. > Type 'IncomingMessage' is missing the following properties from type 'Request>': get, header, accepts, acceptsCharsets, and 29 more. > > io.engine.use(sessionMiddleware); ~~~~~~~~~~~~~~~~~ Related: https://github.com/socketio/socket.io/issues/4644 We could also have use the RequestHandler type from the @types/express-serve-static-core package, but that would add 5 new dependencies. See also: https://github.com/socketio/engine.io/issues/673 --- lib/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/server.ts b/lib/server.ts index 1651a2ed..160b2d88 100644 --- a/lib/server.ts +++ b/lib/server.ts @@ -320,7 +320,7 @@ export abstract class BaseServer extends EventEmitter { * * @param fn */ - public use(fn: Middleware) { + public use(fn: any) { this.middlewares.push(fn); }