-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Open
Labels
to triageWaiting to be triaged by a member of the teamWaiting to be triaged by a member of the team
Description
Describe the bug
Typescript types are not working correctly, specifically for event listeners. on()
and related methods don't seem to accept the callbacks.
For example, I have a client class that I want to expose passthrough methods for event listeners. I defined the passthrough method as
listen<E extends keyof ServerToClientEvents>(eventName: E, callback: ServerToClientEvents[E]) {
this.socket.on(eventName, callback);
}
It yields this error:
TS2345: Argument of type 'ServerToClientEvents[E]' is not assignable to parameter of type 'FallbackToUntypedListener<E extends "connect" | "disconnect" | "connect_error" ? SocketReservedEvents[E] : E extends "server-to-client-1" ? ServerToClientEvents[E] : never>'.
Type '(arg: string[]) => void' is not assignable to type 'FallbackToUntypedListener<E extends "connect" | "disconnect" | "connect_error" ? SocketReservedEvents[E] : E extends "server-to-client-1" ? ServerToClientEvents[E] : never>'.
#5367 is also demonstrated in this repo.
To Reproduce
Reproduction repo: https://github.com/turnerhayes/socket-io-type-confusion
jdugoudr
Metadata
Metadata
Assignees
Labels
to triageWaiting to be triaged by a member of the teamWaiting to be triaged by a member of the team