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

Manually add types to socket.data #4155

Closed
T-Damer opened this issue Nov 4, 2021 · 1 comment · Fixed by #4159
Closed

Manually add types to socket.data #4155

T-Damer opened this issue Nov 4, 2021 · 1 comment · Fixed by #4159
Labels
enhancement New feature or request

Comments

@T-Damer
Copy link

T-Damer commented Nov 4, 2021

Is your feature request related to a problem? Please describe.

I was working with socket.data and noticed that I couldn't define its types. I tried to search the same issue here, but didn't find

Describe the solution you'd like

  • For example I want to do socket.data<User>
  • or maybe pass it when server is being created:
new Server<{user: User}>(server, { cors: { origin: * }, })
  • Or maybe inherit types from usage socket.data = user then socket.data becomes socket.data: {User, ...any} or something like this

Describe alternatives you've considered

Right now I can create a subclass to use it:

interface SocketDataType = { user: User }

export declare class ExtendedSocketServer<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents, ServerSideEvents extends EventsMap = DefaultEventsMap, SocketDataType = any> extends Server<ListenEvents, EmitEvents, ServerSideEvents> {
  of(name: string | RegExp | ParentNspNameMatchFn, fn?: (socket: ExtendedSocketServer<ListenEvents, EmitEvents, ServerSideEvents, SocketDataType>) => void): Namespace<ListenEvents, EmitEvents, ServerSideEvents>;
}

Additional context

Also, I can use the patch-package. I just modified the original node_modules/socket.io/dist/socket.d.ts and run yarn patch-package

@T-Damer T-Damer added the enhancement New feature or request label Nov 4, 2021
@darrachequesne
Copy link
Member

That sounds reasonable 👍 would you have time to open a pull request for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants