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

bug(typings): async event listeners #1486

Closed
roikoren755 opened this issue Aug 12, 2021 · 2 comments
Closed

bug(typings): async event listeners #1486

roikoren755 opened this issue Aug 12, 2021 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@roikoren755
Copy link

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 the socket.on callback parameter should be a function returning void, and not Promise<void>.

According to at least one place in the documentation, it should be possible for listeners to return Promise<void>, and not only void.

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 accept Promise<void> as a return type.

@roikoren755 roikoren755 added the bug Something isn't working label Aug 12, 2021
@darrachequesne
Copy link
Member

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
@darrachequesne
Copy link
Member

This should be fixed by 66e00b7 and socketio/socket.io@ccfd8ca.

Thanks for the detailed report 👍

@darrachequesne darrachequesne added this to the 4.2.0 milestone Aug 30, 2021
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
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants