Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typings issue with io.engine.use #4644

Closed
fastndead opened this issue Feb 28, 2023 · 1 comment
Closed

Typings issue with io.engine.use #4644

fastndead opened this issue Feb 28, 2023 · 1 comment
Labels
to triage Waiting to be triaged by a member of the team

Comments

@fastndead
Copy link

Describe the bug
In the How to use with express-session part of the docs, there's an example for 4.6.0+ version of the library, that suggests to use express middleware with io.engine.use, but typings seem to be off. io.engine.use accepts Middleware type, but express-session middleware type is RequestHandler. Both are middleware handlers but the request types diverge. It leads to this issue:
image

To Reproduce
Socket.IO server version: 4.6.0

Server

import session from "express-session";

const sessionMiddleware = session({
  secret: "changeit",
  resave: false,
  saveUninitialized: false
});

io.engine.use(sessionMiddleware);

Expected behavior
No TS errors. Types are compatible

Platform:

  • Device: MacBook
  • OS: MacOS
@fastndead fastndead added the to triage Waiting to be triaged by a member of the team label Feb 28, 2023
darrachequesne added a commit to socketio/engine.io that referenced this issue May 1, 2023
In order to prevent issues like:

> error TS2345: Argument of type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' is not assignable to parameter of type 'Middleware'.
>  Types of parameters 'req' and 'req' are incompatible.
>  Type 'IncomingMessage' is missing the following properties from type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>': get, header, accepts, acceptsCharsets, and 29 more.
>
>  io.engine.use(sessionMiddleware);
                 ~~~~~~~~~~~~~~~~~

Related: socketio/socket.io#4644

We could also have use the RequestHandler type from the
@types/express-serve-static-core package, but that would add 5 new
dependencies.

See also: https://github.com/socketio/engine.io/issues/673
@darrachequesne
Copy link
Member

For future readers:

This should be fixed by socketio/engine.io@0141951, included in [email protected] (and in Socket.IO v4.6.x).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to triage Waiting to be triaged by a member of the team
Projects
None yet
Development

No branches or pull requests

2 participants