Skip to content

Commit

Permalink
Add missing event type arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeKjaer committed Mar 2, 2021
1 parent 1e2f9cf commit f51c5b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
5 changes: 4 additions & 1 deletion lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export class Client<
* @param conn
* @package
*/
constructor(server: Server<UserEvents, UserEmitEvents>, conn: Socket) {
constructor(
server: Server<UserEvents, UserEmitEvents>,
conn: Socket<UserEvents, UserEmitEvents>
) {
this.server = server;
this.conn = conn;
this.encoder = server.encoder;
Expand Down
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ export class Server<
*/
public of(
name: string | RegExp | ParentNspNameMatchFn,
fn?: (socket: Socket) => void
fn?: (socket: Socket<UserEvents, UserEmitEvents>) => void
): Namespace<UserEvents, UserEmitEvents> {
if (typeof name === "function" || name instanceof RegExp) {
const parentNsp = new ParentNamespace(this);
Expand Down
19 changes: 14 additions & 5 deletions lib/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export class Namespace<

/** @private */
_fns: Array<
(socket: Socket, next: (err?: ExtendedError) => void) => void
(
socket: Socket<UserEvents, UserEmitEvents>,
next: (err?: ExtendedError) => void
) => void
> = [];

/** @private */
Expand Down Expand Up @@ -69,7 +72,10 @@ export class Namespace<
* @public
*/
public use(
fn: (socket: Socket, next: (err?: ExtendedError) => void) => void
fn: (
socket: Socket<UserEvents, UserEmitEvents>,
next: (err?: ExtendedError) => void
) => void
): this {
this._fns.push(fn);
return this;
Expand All @@ -82,7 +88,10 @@ export class Namespace<
* @param fn - last fn call in the middleware
* @private
*/
private run(socket: Socket, fn: (err: ExtendedError | null) => void) {
private run(
socket: Socket<UserEvents, UserEmitEvents>,
fn: (err: ExtendedError | null) => void
) {
const fns = this._fns.slice(0);
if (!fns.length) return fn(null);

Expand Down Expand Up @@ -151,7 +160,7 @@ export class Namespace<
client: Client<UserEvents, UserEmitEvents>,
query,
fn?: () => void
): Socket {
): Socket<UserEvents, UserEmitEvents> {
debug("adding socket to nsp %s", this.name);
const socket = new Socket(this, client, query);
this.run(socket, (err) => {
Expand Down Expand Up @@ -194,7 +203,7 @@ export class Namespace<
*
* @private
*/
_remove(socket: Socket): void {
_remove(socket: Socket<UserEvents, UserEmitEvents>): void {
if (this.sockets.has(socket.id)) {
this.sockets.delete(socket.id);
} else {
Expand Down

0 comments on commit f51c5b8

Please sign in to comment.