Skip to content

Issues with io.on() typings #3833

Closed
@westy92

Description

Describe the bug
After upgrading to socket.io 4.0.0, my code no longer compiles when using string enums for event names.

To Reproduce

Please fill the following code example:

Socket.IO server version: 4.0.0
TypeScript@4.2.3

Server

import { Server } from "socket.io";

const io = new Server(3000, {});

// this works fine
io.on("connection", (socket) => {});

enum Event {
    CONNECTION = "connection",
}
// Fails to compile!
// Argument of type '(socket:Socket) => void' is not assignable to parameter of type 'never'.
// ts(2345)
io.on(Event.CONNECTION, (socket) => {});

Client
N/A

Expected behavior
I expect my code to compile like it does for version 2.x and 3.x.

Platform:
N/A

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions