Unable to type middleware properly in typescript
Describe the bug
(socket: Socket, next: (err?:ExtendedError)=> void
When trying to type a middleware function for socket IO the above gives an error that ExtendedError is only defined internally
To Reproduce
in some file create your middle ware const myMiddlewarefunc = (ocket: Socket, next: (err?:ExtendedError)=> void) = > { // do something }
in main file probably index.ts io.use(myMiddlewarefunc)
Socket.IO server version: x.y.z
"socket.io": "^4.7.2",
I have the same problem.
Hi! ExtendedError is indeed not currently exported.
As a workaround, you can simply use an Error type:
const myMiddlewareFunc = (socket: Socket, next: (err?: Error) => void) => {
// do something
}
@darrachequesne hey, the problem is, the normal error type does not have the data property.
For future readers:
The ExtendedError type is now exported: https://github.com/socketio/socket.io/commit/32c761f02fb67625297ed6644f744b7647662e65
Included in [email protected].