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

Unable to use HttpResponse.error() with TypeScript #2130

Open
4 tasks done
jacquesg opened this issue Apr 11, 2024 · 3 comments · May be fixed by #2132
Open
4 tasks done

Unable to use HttpResponse.error() with TypeScript #2130

jacquesg opened this issue Apr 11, 2024 · 3 comments · May be fixed by #2132
Labels
api:graphql bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node scope:typescript

Comments

@jacquesg
Copy link

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 18 or higher

Node.js version

v20.12.1

Reproduction repository

https://codesandbox.io/p/sandbox/friendly-pare-8tkfgz?file=%2Fmocks%2Fhandlers.ts

Reproduction steps

npx tsc

Current behavior

Adding a return HttpResponse.error() results in a TS error:

mocks/handlers.ts:10:31 - error TS2345: Argument of type '() => Response' is not assignable to parameter of type 'GraphQLResponseResolver<GraphQLQuery, GraphQLVariables>'.
  Type 'Response' is not assignable to type 'AsyncResponseResolverReturnType<GraphQLResponseBody<GraphQLQuery>>'.
    Property '[bodyType]' is missing in type 'Response' but required in type 'StrictResponse<GraphQLResponseBody<GraphQLQuery>>'.

10   graphql.query('ListMovies', () => {
                                 ~~~~~~~

Expected behavior

No error.

@jacquesg jacquesg added bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node labels Apr 11, 2024
@kettanaito
Copy link
Member

Hi, @jacquesg! Thanks for reporting this. This looks like a bug and we should fix it.

Do you mind writing a simple type test for this? Putting it somewhere in this test suite would be the best. You can then open a PR with a failing test and we can investigate it from there. Let me know if that sounds interesting to you!

@jacquesg
Copy link
Author

Hi @kettanaito, I've submitted PR #2132.

@kettanaito
Copy link
Member

I shared a solution and my concerns with it in the PR.

@kettanaito kettanaito linked a pull request Jun 1, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api:graphql bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node scope:typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants