-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Breaking Changes in 2.8.0 for TypeScript users? #903
Comments
I encountered the same issue. |
Also |
Hi @MarcusNotheis! The result and error parameters have indeed been swapped to match with the useQuery signature. But if you type the mutation function then it should not be needed to explicitly define the generics:
The |
…ch fails Enables the `throwOnError` configuration option for `useQuery.refetch` that has as of yet only been present in the documentation but not in the code. Relates to: TanStack#903 TanStack#843
Changing the 20bbedf#diff-eeb1adcf0c71d7ca0cd3b2e1e8fe03f9R181 where the catch block wasn't previously returning. Is this the expected behaviour, where usages of |
Hi @bmaclean! The runtime behaviour has not changed with the new types, meaning the |
#907) * feat(useQuery): allow useQuery.refetch to throw an error when the fetch fails Enables the `throwOnError` configuration option for `useQuery.refetch` that has as of yet only been present in the documentation but not in the code. Relates to: #903 #843 * refactor(useQuery): move "useQuery.refetch" options to dedicated type
I have created function that use |
@ThibautMarechal I believe you're looking for |
Yes, the types had breaking changes, but the public API did not. Among many other libraries, React Query does not include Types when determining semver changes. Since TypeScript is an extremely strict compilation language, any and all type changes would technically be considered breaking changes, which obviously wouldn't work. As a TypeScript user, you should probably have your dependencies locked down to specific patch versions With that said, type changes are handled as |
Oh man I kinda understand your explanation but I can't tell you how much work this has created for us! We have react query as a peer dependency in about 20 repos, where 15 of them were written during 2.7 and the others 2.8+. Trying to use them all in a single application has caused hundreds of ts errors. Errors that arise due to you tightening up an existing type - that's awesome - they almost always shed light on an oversight by the consumer. But when you're not doing breaking changes after renaming an exported type, that's rough! In my books that's totally a change to the public API |
Describe the bug
It looks like that there are breaking changes in
2.8.0
for TypeScript users inuseMutation
:In
2.7.1
, use Mutation was typed as:https://unpkg.com/browse/react-query@2.7.1/types/index.d.ts
Now in
2.8.0
, TVariables and TError have swapped their places:https://unpkg.com/browse/react-query@2.8.0/types/react/useMutation.d.ts
This results in TS Errors for the code which was working in 2.7.1:
Error:
TS2339: Property 'items' does not exist on type 'undefined'.
By adding e.g.
any
as second generic to theuseMutation
function everything is working as expected again.Expected behavior
I would have expected that the signature of the method didn't change in a minor release. Anyhow, I think this is not a really big issue which would require a rollback of that change, but it should be mentioned in the release for example so that TypeScript users know how to deal with this issue.
The text was updated successfully, but these errors were encountered: