Typescript: Allow extending socket's incoming request separately from Express
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 63.2k
- Forks
- 10.3k
- Avg merge
- 11d 20h
- Merged PRs (30d)
- 2
Description
PR here https://github.com/socketio/socket.io/pull/4787
Is your feature request related to a problem? Please describe.
Use own interface for Socket request to allow extending the request interface with custom properties without polluting the IncomingMessage type which is also used by Express/Passport.
Using socket.io with passport middlewares causes issues when using the same 'userProperty' key is used for both - for example by extending IncomingMessage { user: Express.User } we break passport's isAuthenticated() function, because now typescript thinks that the request is always of the type AuthenticatedRequest as IncomingMessage always has a user property on itself. To fix this, I believe we should be able to extend only the request type inside socket.io -> SocketRequest.
Describe the solution you'd like
Use own interface for Socket request to allow extending the request interface independently of Express.
Describe alternatives you've considered
I haven't found any reasonable workarounds.
Additional context
See https://github.com/socketio/socket.io/pull/4787
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading pull request #4787 and the issue’s TypeScript request-type discussion. Confirm how Socket.IO request typing currently interacts with Express and Passport, then verify that the requested separation allows Socket.IO request properties to be extended without changing IncomingMessage behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- express, nodejs, typescript
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100