-
-
Notifications
You must be signed in to change notification settings - Fork 520
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
test: add type test for HttpResponse.error #2132
base: main
Are you sure you want to change the base?
Conversation
jacquesg
commented
Apr 13, 2024
•
edited by kettanaito
Loading
edited by kettanaito
- Fixes Unable to use HttpResponse.error() with TypeScript #2130
As expected, the CI is failing now due to the type error :) |
Thanks for writing the tests, @jacquesg! I think this hints at a more fundamental issue with how we annotate responses in MSW. See, this is the underlying type that everything depends on: msw/src/core/handlers/RequestHandler.ts Lines 38 to 45 in 7cf34c1
And it expects a The issue happens when the response body type is supposed to be a union of types, like in case of GraphQL responses:
I don't believe that type likes the union as the argument. We also don't teach it how to handle unions by doing something like Here's an isolated playground. |
We can implement a fix like so and it will work. It creates a different problem violating this expectation: msw/test/typings/graphql.test-d.ts Lines 97 to 103 in 7cf34c1
Because the union produced to support Preventing wrong mocked responses on the type level is a great feature to have. Unfortunately, |