socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

Property 'handleUpgrade' does not exist on type 'BaseServer'.ts(2339)

Open GreenTea124 opened this issue 2 years ago • 5 comments

Describe the bug When you do this:

import {Server} from "socket.io";

const io = new Server({
	cors: { origin: "*" }
});

//...
io.engine.handleUpgrade(req, socket, head);

Code works but TypeScript produces following error:

Property 'handleUpgrade' does not exist on type 'BaseServer'.ts(2339)

Version

"socket.io": "^4.6.1",
"socket.io-client": "^4.6.1",

GreenTea124 avatar Apr 15 '23 00:04 GreenTea124

The BaseServer class exists on the engine.io codebase. This is more likely a problem with enginge.io, an engine used by Socket.io under the hood. Can you report this issue in the engine.io repo?

haneenmahd avatar Apr 29 '23 20:04 haneenmahd

I don't think there is any problem with the types, I checked it out and it works fine. Can you try and re-install the packages?

haneenmahd avatar Apr 29 '23 20:04 haneenmahd

The issue is that the BaseServer class (used here) does not expose a handleUpgrade() method, only Server does.

darrachequesne avatar May 01 '23 06:05 darrachequesne

As a temporary workaround, one could use:

import { Server } from "socket.io";
import { Server as Engine } from "engine.io";

const io = new Server({
    cors: { origin: "*" }
});

//...
(io.engine as Engine).handleUpgrade(req, socket, head);

darrachequesne avatar May 01 '23 06:05 darrachequesne

Any update on this?

pvarouktsis avatar May 22 '24 09:05 pvarouktsis