-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Type issues with emit
and emitWithAck
#4813
Comments
Hi! Thanks for this detailed analysis 👍 I think most of the issues come from the fact that calling So, for example: // INVALID (will time out directly anyway)
io.emit('withAck', 'hello', (...args) => { });
// VALID
io.timeout(1).emit('withAck', 'hello', (...args) => { }); Also, broadcasting with an acknowledgement from each client is only meant to be used with one callback argument. This was to prevent surprising behaviors such as: export interface ServerToClientEvents {
// VALID
withAck: (d: string, callback: (e: number) => void) => void;
// INVALID
withAck2: (d: string, callback: (e: number, f: string) => void) => void;
}
io.timeout(5000).emit("withAck", "hello", (err, responses) => {
// responses: number[]
// responses[0]: number
});
io.timeout(5000).emit("withAck2", "hello", (err, responses) => {
// responses: [number, string][]
// responses[0]: [number, string]
}); Does that make sense? |
The main reason why I put up this issue and the accompanying pull request is that the Typescript Types on this library don't reflect the reality of the library, which makes them somewhere between dangerous (when a type exists, but is completely wrong) to pointless (when a type comes back as
I had incorrectly assumed that emitting to multiple clients without timeout would just never timeout, thanks for the clarification. I completely missed the warning alert on the docs page for Here are some of my thoughts on how to align the type defintions with the reality of the library based on the current behaviors (beyond what I currently have in my PR): A fair amount of this is based on my understanding that it is currently impossible to add a timeout without creating an instance of the
|
@ZachHaber that sounds great 👍 |
Describe the bug
When using
emit
,emitWithAck
, and the server side variants, there are issues with the types of Broadcaster, Server, Namespace, and Socket types.To Reproduce
Socket.IO server version:
4.7.2
Server
Socket.IO client version:
x.y.z
Client
I haven't checked on the client, but I assume the same types are used on here too (to some extent)
Expected behavior
Type definitions should be consistent with what socket.io is doing so that we can fully rely on them. As of the moment, they are wrong in a few places that are either frustrating (
any
instead of a real type) or problematic (number
instead ofnumber[]
).Platform:
Additional context
I have some first passes at solving some of these issues that I can work towards improving and turning into a PR, if that's desired.
The text was updated successfully, but these errors were encountered: