-
Notifications
You must be signed in to change notification settings - Fork 565
Closed
Description
Describe the bug
The Socket.IO documentation suggests setting the request property of the socket object received with the connection event to null. But the types as defined do not allow setting that property from a TypeScript program.
To Reproduce
Note that this is a Socket.IO program, because it is taken from the Socket.IO documentation, but it seems clear that the issue comes from the Socket type declared in Engine.IO, which is why I'm opening this issue here.
Socket.IO server version: 4.7.4
Server
import { Server } from "socket.io";
const io = new Server(8080);
io.on("connection", (socket) => {
console.log(`connect ${socket.id}`);
socket.request = null;
});When compiling with tsc server.ts here is the result:
server.ts:7:12 - error TS2540: Cannot assign to 'request' because it is a read-only property.
7 socket.request = null;
~~~~~~~
Found 1 error in server.ts:7
Expected behavior
The request property should not be marked read-only, in order to allow this code to compile.
Workaround
Bypassing the restriction works:
(socket as any).request = null;
Metadata
Metadata
Assignees
Labels
No labels