Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript error with default events using enum #3885

Closed
tannerkrewson opened this issue Apr 18, 2021 · 2 comments
Closed

Typescript error with default events using enum #3885

tannerkrewson opened this issue Apr 18, 2021 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@tannerkrewson
Copy link

Describe the bug
I'm using Typescript enums for my socket events. I made my own for connect, disconnect, etc. like this:

export enum SocketEvent {
    CONNECT = "connect",
    DISCONNECT = "disconnect",
    RECONNECT = "reconnect",
}

Not shown, I also have my own SocketEvent enums for my custom events. Those do not have this error.

Those three cause this error:

pages/find.tsx:68:43 - error TS2345: Argument of type '(reason: string) => void' is not assignable to parameter of type 'never'.

68         socket.on(SocketEvent.DISCONNECT, (reason: string) => {
                                             ~~~~~~~~~~~~~~~~~~~~~

utils/useRocketcrabClientSocket.ts:29:40 - error TS2345: Argument of type '() => void' is not assignable to parameter of type 'never'.

29         socket.on(SocketEvent.CONNECT, () => setSocketConnected(true));
                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

utils/useRocketcrabClientSocket.ts:49:43 - error TS2345: Argument of type '(reason: any) => void' is not assignable to parameter of type 'never'.

49         socket.on(SocketEvent.DISCONNECT, (reason) => {
                                             ~~~~~~~~~~~~~

utils/useRocketcrabClientSocket.ts:74:45 - error TS2345: Argument of type '() => void' is not assignable to parameter of type 'never'.

74         socket.io.on(SocketEvent.RECONNECT, () => {

To Reproduce

Use an enum with the string for the default events.

Socket.IO server version: 4.0.1

Expected behavior
A clear and concise description of what you expected to happen.

Platform:
Win 10, Node 14, Typescript 4.2.4

@tannerkrewson tannerkrewson added the bug Something isn't working label Apr 18, 2021
@tannerkrewson
Copy link
Author

Is this the same as #3834 ? I'm definetely on 4.0.1 🤔

@darrachequesne
Copy link
Member

The fix was not replicated to the client, it is now: socketio/socket.io-client@5394669

Included in [email protected].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants