From e5c62cad60fc7d16fbb024fd9be1d1880f4e6f5f Mon Sep 17 00:00:00 2001 From: SyedTayyabUlMazhar <43899564+SyedTayyabUlMazhar@users.noreply.github.com> Date: Tue, 20 Jun 2023 10:49:02 +0500 Subject: [PATCH] fix: remove the Partial modifier from the socket.data type (#4740) Wrapping SocketData with Partial causes issues when reading data even if you've made sure to pass all values. If someone want to make their type Partial or make only a few properties optional, they can do so in their own type instead. Related: https://github.com/socketio/socket.io/issues/4537 --- lib/socket.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/socket.ts b/lib/socket.ts index fa6333e0f5..89b5eeaf31 100644 --- a/lib/socket.ts +++ b/lib/socket.ts @@ -202,7 +202,7 @@ export class Socket< * Additional information that can be attached to the Socket instance and which will be used in the * {@link Server.fetchSockets()} method. */ - public data: Partial = {}; + public data: SocketData = {} as SocketData; /** * Whether the socket is currently connected or not. * @@ -260,7 +260,7 @@ export class Socket< this.id = previousSession.sid; this.pid = previousSession.pid; previousSession.rooms.forEach((room) => this.join(room)); - this.data = previousSession.data as Partial; + this.data = previousSession.data as SocketData; previousSession.missedPackets.forEach((packet) => { this.packet({ type: PacketType.EVENT,