Property 'session' does not exist on type 'IncomingMessage'.ts(2339) any #5173
Unanswered
Anand-Keshavan
asked this question in
Q&A
Replies: 1 comment
-
Hi! You need to cast the import { type Request } from "express";
io.on("connection", (socket) => {
const req = socket.request as Request;
// ...
}); Reference: https://socket.io/how-to/use-with-express-session |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I get the above error when I try to use the express-session example ( typescript) in the documentation. Here is the code:
`declare module "express-session" {
interface SessionData {
}
const sessionMiddleware = session({
secret: "losgatos",
resave: true,
saveUninitialized: true,
});
const app = express();
app.use(sessionMiddleware);
const httpServer = createServer(app);
const io = new Server(httpServer, { /* options */ });
io.engine.use(sessionMiddleware);
o.on("connection", (socket) => {
const sessionId = socket.request.session.id. // <---- error here
...
`
package versions:
"@types/express": "^4.17.21", "@types/express-session": "^1.18.0", "express": "^4.19.2", "express-session": "^1.18.0", "socket.io": "^4.7.5",
Beta Was this translation helpful? Give feedback.
All reactions