Skip to content

send functions should have generic types #3742

@MickL

Description

@MickL

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

Currently functions like emit are not typable:

socket.emit('my-event-name', dto);

This applies to both socket.io server and client.

Describe the solution you'd like
I would like to have generic types on all emit functions to (optionally) type the send-object and the response-object:

socket.emit<void, MyDtoInterface>('my-event-name', dto);
socket.emit<MyResponseDtoInterface, MyDtoInterface>('my-event-name', dto, responseDto => {
   // ...
});

Now if an interface changes TypeScript throws an error if the objects are not updated.

Suggested solution
Functions could look something like this:

// Server:
emit<TInput = any>(ev: string, data: TInput);

// Client:
emit<TResult = any, TInput = any>(ev: string, data: TInput, (response: TResult) => {});

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions