Skip to content

Commit e5c62ca

Browse files
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: #4537
1 parent 01d3762 commit e5c62ca

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/socket.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export class Socket<
202202
* Additional information that can be attached to the Socket instance and which will be used in the
203203
* {@link Server.fetchSockets()} method.
204204
*/
205-
public data: Partial<SocketData> = {};
205+
public data: SocketData = {} as SocketData;
206206
/**
207207
* Whether the socket is currently connected or not.
208208
*
@@ -260,7 +260,7 @@ export class Socket<
260260
this.id = previousSession.sid;
261261
this.pid = previousSession.pid;
262262
previousSession.rooms.forEach((room) => this.join(room));
263-
this.data = previousSession.data as Partial<SocketData>;
263+
this.data = previousSession.data as SocketData;
264264
previousSession.missedPackets.forEach((packet) => {
265265
this.packet({
266266
type: PacketType.EVENT,

0 commit comments

Comments
 (0)