Property 'handleUpgrade' does not exist on type 'BaseServer'.ts(2339)
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",
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?
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?
The issue is that the BaseServer class (used here) does not expose a handleUpgrade() method, only Server does.
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);
Any update on this?