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

chore(types): make RemoteSocket.data type safe #4234

Merged

Conversation

OrkhanAlikhanov
Copy link
Contributor

@OrkhanAlikhanov
Copy link
Contributor Author

Ah formatting. Will fix soon

@@ -769,7 +769,7 @@ export class Server<
*
* @public
*/
public fetchSockets(): Promise<RemoteSocket<EmitEvents>[]> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we would have:

const sockets = await io.fetchSockets();

// with the BroadcastOperator
const sockets = await io.in("room-1").fetchSockets<SocketData>();

Is that right?

Copy link
Contributor Author

@OrkhanAlikhanov OrkhanAlikhanov Jan 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. We loss the SocketData type when BroadcastOperator is created, so it has to be specified. Otherwise it will default to any

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, I think it would make more sense to go with your first solution here, so we have the same API with and without operator (like to() or except()).

const sockets = await io.fetchSockets();
const sockets = await io.in("room-1").fetchSockets(); // no additional types

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me. Will update the PR

@darrachequesne darrachequesne merged commit 770ee59 into socketio:master Jan 6, 2022
@darrachequesne
Copy link
Member

@OrkhanAlikhanov awesome, thanks a lot 👍

@darrachequesne darrachequesne added this to the 4.4.1 milestone Jan 6, 2022
dzad pushed a commit to dzad/socket.io that referenced this pull request May 29, 2023
@OrkhanAlikhanov OrkhanAlikhanov deleted the remote-socket-data-type branch September 6, 2023 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants