Skip to content

Allow fetchclient's data to be set to success type only #2047

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

Open
soartec-lab opened this issue Apr 19, 2025 · 3 comments
Open

Allow fetchclient's data to be set to success type only #2047

soartec-lab opened this issue Apr 19, 2025 · 3 comments
Assignees
Labels
fetch Fetch client related issue

Comments

@soartec-lab
Copy link
Member

Background

In #1885, we defined the type of response's data and status as a combination.
When used with the fetch client, this is a more accurate type definition.

However, when used as an HTTP client such as swr or react-query, it becomes a union type of 200 and 400, and the type cannot be specified. And in those libraries, it is common to use exceptions for cases other than 200 and refer to data only when it is 200.

For example, swr:

https://swr.vercel.app/docs/error-handling

Proposal

There are cases where you want to define only 200 data as before and make only the status a union type, so by making these options selectable, we would like to maintain the format before #1885.

@soartec-lab soartec-lab added the fetch Fetch client related issue label Apr 19, 2025
@soartec-lab
Copy link
Member Author

Hi @AllieJonsson what do you think about this?

@AllieJonsson
Copy link
Contributor

Seems very reasonable. Is there a need to have this as a setting? Im thinking maybe this should be the behavior when using fetch as httpClient, and keep the behavior introduced in #1885 when using fetch as client?

@soartec-lab
Copy link
Member Author

@AllieJonsson
Although swr and tanstack query are recommended, they are not mandatory. There may be cases where you want to use composite response types while using those libraries, so we want to maintain the option for users.

@AllieJonsson AllieJonsson self-assigned this Apr 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fetch Fetch client related issue
Projects
None yet
Development

No branches or pull requests

2 participants