I am using Socket.io v4.0.1 with typescript and a node/express server which works as intended. The problem is that on connection I want to emit to the client socket its sessionID and userID, which are addition attributes on my server socket instance, but typescript is throwing the following type errors.
io.on("connection", (socket: Socket): void => {
console.log(socket.id);
socket.emit("session", {
sessionID: socket.sessionID, // property sessionID does not exist on type Socket<DefaultEventsMap,DefaultEventsMap>
userID: socket.userID,// property userID does not exist on type Socket<DefaultEventsMap,DefaultEventsMap>
});
});
Is there any way to add this additional attributes to the type definition without changing the type definitions itself (@types/socket.io) ?