Skip to content

Commit

Permalink
refactor(typings): export Socket class
Browse files Browse the repository at this point in the history
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) => {
  // ...
});
```
  • Loading branch information
darrachequesne committed Oct 17, 2020
1 parent 7603da7 commit 0d74f29
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions test/socket.io.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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();
});
Expand Down

0 comments on commit 0d74f29

Please sign in to comment.