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
PacketType.CONNECT_ERROR adds err.data but downstream interface SocketReservedEventsMap does not expect that #5542
Describe the bug
The connect_error event callback argument is typed as standard JavaScript Error in SocketReservedEventsMap. As a result, accessing err.data in any downstream function produces a compiler error (Property 'data' does not exist on type 'Error'), even though err.data is used on the onpacket function in socket.io-client/lib/socket.ts.
Also, the PacketType.CONNECT_ERROR case relies on a // @ts-ignore to attach packet.data.data to the Error instance, which is not best practice.
To Reproduce
Socket.IO server version: 4.7.5 (or any v4.x)
Server
import{Server}from"socket.io";// Creates the server and binds it to port 3000 automaticallyconstio=newServer(3000,{cors: {origin: "*"// Essential if testing from a browser app or a different origin}});interfaceExtendedErrorextendsError{data?: any;}// Blocks every connection with your error payloadio.use((socket,next)=>{// ExtendedError required here, or @ts-ignore the `err.data` assignmentconsterr=newError("not authorized")asExtendedError;err.data="some data"// Also note that code in /packages/socket.io-client/lib/socket.ts assumes a message as well// err.message = "Retry later"next(err);});console.log("Standalone Socket.IO server running on port 3000");
Socket.IO client version: 4.7.5 (or any v4.x)
Client
import{io}from"socket.io-client";constsocket=io('http://localhost:3000');socket.on("connect_error",(err)=>{// TypeScript error: Property 'data' does not exist on type 'Error'.console.log(err.data);});
The argument in connect_error above should be typed with an interface that includes data, and likely extends Error (unless a more creative solution is found), matching the expectations expressed in the official Socket.IO documentation and removing the need for any downstream consumer casts ((err as any).data) and/or the internal // @ts-ignore in socket.ts.
Hi team, I would like to align the TypeScript definitions for connect_error.
In SocketReservedEventsMap, the connect_error callback argument is typed as a standard Error, but Socket.IO attaches custom payload data (err.data) via PacketType.CONNECT_ERROR. I can update the type definitions in packages/socket.io-client to type connect_error with optional data properties, with test verification.
Activity
webdevsamran commentedon Sep 6, 2026
Hi team, I would like to align the TypeScript definitions for
connect_error.In
SocketReservedEventsMap, theconnect_errorcallback argument is typed as a standardError, but Socket.IO attaches custom payload data (err.data) viaPacketType.CONNECT_ERROR. I can update the type definitions inpackages/socket.io-clientto typeconnect_errorwith optionaldataproperties, with test verification.Could you please assign this to me? Thanks!
fix(sio-client/types): export ExtendedError for connect_error event (#…
darrachequesne commentedon Sep 25, 2026
Released in
socket.io-client@4.8.4.Release notes: https://github.com/socketio/socket.io/releases/tag/socket.io-client%404.8.4