From 0d74f290cdb903152950bfa6e82beb8deb9c1070 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Sat, 17 Oct 2020 02:50:48 +0200 Subject: [PATCH] refactor(typings): export Socket class In order to be able to cast it on the argument of the "connect" event: ```js import { Socket } from "socket.io"; io.on("connect", (socket: Socket) => { // ... }); ``` --- lib/index.ts | 2 ++ test/socket.io.ts | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index ea05298b10..19825dd96e 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -709,3 +709,5 @@ emitterMethods.forEach(function(fn) { module.exports = (srv?, opts?) => new Server(srv, opts); module.exports.Server = Server; + +export { Socket }; // for "connect" event typing diff --git a/test/socket.io.ts b/test/socket.io.ts index 4dc69ef777..34b78eba77 100644 --- a/test/socket.io.ts +++ b/test/socket.io.ts @@ -1,6 +1,6 @@ "use strict"; -import { Server } from ".."; +import { Server, Socket } from ".."; import { createServer } from "http"; import fs = require("fs"); import { join } from "path"; @@ -357,7 +357,7 @@ describe("socket.io", () => { const sio = new Server(srv); srv.listen(() => { const socket = client(srv); - sio.on("connection", socket => { + sio.on("connection", (socket: Socket) => { expect(socket).to.be.a(Socket); done(); });