mswjs / mswjs/interceptors

`@typescript-eslint/no-misused-promises` with async listener

Open
#736 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
687
Forks
174
Avg merge
3h 40m
Merged PRs (30d)
14

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the lint error in the linked msw-interceptors-listener-type repository using XMLHttpRequestInterceptor. Inspect the listener type exposed by XMLHttpRequestInterceptor and compare it with the typing in strict-event-emitter. Done means the async listener is accepted without the reported @typescript-eslint/no-misused-promises error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.