You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot set socket.request to null because the property is read-only #696
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.
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.
Activity
Make Socket.request writable
fix(types): make socket.request writable (#697)
sayhicoelho commentedon Jul 18, 2024
Still can't set it to
nullon the latest version v4.7.5 using pure Javascript.Code:
Output:
darrachequesne commentedon Jul 19, 2024
@sayhicoelho this should work:
In your example:
socket.requestis a reference to the underlyingrequestobject: https://github.com/socketio/socket.io/blob/1f09a3e97950663cd7c62a34c74af60dad8f0346/packages/socket.io/lib/socket.ts#L991-L996