From 6652a3fe9ef09c81b6a86c656d84e72b51344c48 Mon Sep 17 00:00:00 2001 From: Tristan F Date: Wed, 11 Jan 2023 04:45:57 -0500 Subject: [PATCH] refactor(typings): add types for io.engine (#4591) This adds typings for the socket.io engine field, which offers better IntelliSense when retrieving the server, as well as more confidence on the developer-side of what types of fields are entering the server. Related: https://github.com/socketio/socket.io/issues/4590 --- lib/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 2ec56d08ae..fa18b7670c 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -31,6 +31,7 @@ import { EventNames, } from "./typed-events"; import { patchAdapter, restoreAdapter, serveFile } from "./uws"; +import type { BaseServer } from "engine.io/build/server"; const debug = debugModule("socket.io:server"); @@ -127,7 +128,7 @@ export class Server< * const clientsCount = io.engine.clientsCount; * */ - public engine: any; + public engine: BaseServer; /** @private */ readonly _parser: typeof parser; @@ -582,10 +583,10 @@ export class Server< /** * Binds socket.io to an engine.io instance. * - * @param {engine.Server} engine engine.io (or compatible) server + * @param engine engine.io (or compatible) server * @return self */ - public bind(engine): this { + public bind(engine: BaseServer): this { this.engine = engine; this.engine.on("connection", this.onconnection.bind(this)); return this;