Skip to content

fix(HttpResponse): accept interfaces as json response-data type#1481

Merged
kettanaito merged 1 commit into
mswjs:feat/standard-apifrom
christoph-fricke:fix/response-with-interface
Nov 28, 2022
Merged

fix(HttpResponse): accept interfaces as json response-data type#1481
kettanaito merged 1 commit into
mswjs:feat/standard-apifrom
christoph-fricke:fix/response-with-interface

Conversation

@christoph-fricke

Copy link
Copy Markdown
Contributor

This PR introduces a fix for an issue discussed with the upcoming standard-api. The relevant discussion can be found here: #1464 (comment)
TLDR: Objects that are typed with an interface cannot be assigned to HttpResponse.json.

This PR changes the generic of HttpResponse.json to extend DefaultBodyType instead of the similar yet slightly different union. I think it makes more sense (and fixes the issue), because the response generic of resolver functions and generic of StrictResponse also extend DefaultBodyType.

@codesandbox-ci

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1f92748:

Sandbox Source
MSW React Configuration

@kettanaito kettanaito left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply great! Thanks, @christoph-fricke 👏

If you spot any other type issues with the next release, please let me know/open a pull request. Let's build the future of API mocking together.

@kettanaito kettanaito merged commit 2f8bf27 into mswjs:feat/standard-api Nov 28, 2022
@christoph-fricke christoph-fricke deleted the fix/response-with-interface branch November 28, 2022 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants