socketio / socketio/socket.io

Typescript: Allow extending socket's incoming request separately from Express

Open
#4,795 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.