-
Notifications
You must be signed in to change notification settings - Fork 3k
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
bug(typings): async event listeners #1486
Comments
Hi! I could reproduce the issue, I'm working on this. |
darrachequesne
added a commit
to socketio/socket.io
that referenced
this issue
Aug 30, 2021
So that: ```ts socket.on("my-event", async () => { // ... }); ``` is valid under the @typescript-eslint/no-misused-promises rule. Related: socketio/socket.io-client#1486
darrachequesne
added a commit
that referenced
this issue
Aug 30, 2021
So that: ```ts socket.on("my-event", async () => { // ... }); ``` is valid under the @typescript-eslint/no-misused-promises rule. Related: #1486
This should be fixed by 66e00b7 and socketio/socket.io@ccfd8ca. Thanks for the detailed report 👍 |
sunrise30
added a commit
to sunrise30/socket.io-client
that referenced
this issue
Jan 8, 2022
So that: ```ts socket.on("my-event", async () => { // ... }); ``` is valid under the @typescript-eslint/no-misused-promises rule. Related: socketio/socket.io-client#1486
dzad
pushed a commit
to dzad/socket.io
that referenced
this issue
May 29, 2023
So that: ```ts socket.on("my-event", async () => { // ... }); ``` is valid under the @typescript-eslint/no-misused-promises rule. Related: socketio/socket.io-client#1486
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
Trying to update
socket.io-client
from v3.1.3 to v4.1.3 in one of my typescript projects. I have async event listeners defined at the client side. This code worked fine in v3, and might be the same in v4, but the@typescript-eslint/no-misused-promises
rule started reporting that thesocket.on
callback parameter should be a function returningvoid
, and notPromise<void>
.According to at least one place in the documentation, it should be possible for listeners to return
Promise<void>
, and not onlyvoid
.If I use the
Socket
class' generics to defined possible listen and emit events, I can return whatever I want in the listener, provided it fits the return type I define.To Reproduce
Simply use an async listener anywhere. The typescript compiler will be ok with it, but
@typescript-eslint/no-misused-promises
flags it as an issue.Expected behavior
The default listener type, provided by
FallbackToUntypedListener
, should acceptPromise<void>
as a return type.The text was updated successfully, but these errors were encountered: