Skip to content

@typescript-eslint/no-misused-promises with async listener #736

@UnsungHero97

Description

@UnsungHero97

We've established that listeners can be async but I think the listener type might be wrong:

const interceptor = new XMLHttpRequestInterceptor();
interceptor.on('request', async ({ controller, request }) => {
  const response = await getResponse(handlers, request);
  controller.respondWith(response ?? Response.json({ error: 'msw interceptor error' }));
});

ESlint is not happy with the async listener:

/Users/hristo/dev/msw-interceptors-listener-type/src/main.tsx
  13:27  error  Promise returned in function argument where a void return was expected  @typescript-eslint/no-misused-promises

✖ 1 problem (1 error, 0 warnings)
Image

Here's a repo to reproduce the issue:

https://github.com/UnsungHero97/msw-interceptors-listener-type

This might be a type issue in strict-event-emitter but I'm seeing it by using XMLHttpRequestInterceptor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions