Describe the bug
Emitting an event using a timeout and acknowledgement causes the acknowledgement function to change its arguments list, so that Error is first argument. This breaks the Typescript definitions. See below for more details:
To Reproduce
Socket.IO client version: 4.5.2
Client
import { io } from "socket.io-client";
interface ClientToServerEvents {
"withAck": (callback: (data: any) => void) => void;
}
const socket: Socket<ServerToClientEvents, ClientToServerEvents> = io("ws://localhost:3000/", {});
socket.on("connect", () => {
socket.timeout(5000).emit("withAck", (error, data) => { // typescript throws here, since the function takes just one parameter as per the ClientToServerEvents interface
/* If .timeout() is not used, then the first argument is data.
If .timeout() is used, then first argument is error, second one is data.
This breaks the ClientToServerEvents interface.
If you change the ClientToServerEvents interface to have an error argument,
then calling the callback from the server breaks, since there data is always first parameter.
You need to use different interfaces for client and server.
*/
});
});
Expected behavior
It should be possible to define one ClientToServerEvents interface and use it both with client and server, irrespective if events are emitted with timeout or not.
Describe the bug
Emitting an event using a timeout and acknowledgement causes the acknowledgement function to change its arguments list, so that Error is first argument. This breaks the Typescript definitions. See below for more details:
To Reproduce
Socket.IO client version:
4.5.2Client
Expected behavior
It should be possible to define one ClientToServerEvents interface and use it both with client and server, irrespective if events are emitted with timeout or not.