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
This commit is contained in:
Tristan F
2023-01-11 04:45:57 -05:00
committed by GitHub
parent 547c541fb9
commit d4a9b2cdcb

View File

@@ -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;