-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Closed
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
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
Labels
enhancementNew feature or requestNew feature or request