question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Breaking Changes in 2.8.0 for TypeScript users?

See original GitHub issue

Describe the bug It looks like that there are breaking changes in 2.8.0 for TypeScript users in useMutation:

In 2.7.1, use Mutation was typed as:

export function useMutation<TResult, TVariables = undefined, TError = Error, TSnapshot = unknown>(
  mutationFn: MutationFunction<TResult, TVariables, TError, TSnapshot>,
  mutationOptions?: MutationOptions<TResult, TVariables, TError, TSnapshot>
): MutationResultPair<TResult, TVariables, TError>

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:


export declare function useMutation<TResult, TError = unknown, TVariables = undefined, TSnapshot = unknown(
  mutationFn: MutationFunction<TResult, TVariables>, 
  config?: MutationConfig<TResult, TError, TVariables, TSnapshot>
): MutationResultPair<TResult, TError, TVariables, TSnapshot>;

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:

return useMutation<void, { items: string[]; otherItems: string[] }>(async ({ items, otherItems }) => {
...
});

Error: TS2339: Property 'items' does not exist on type 'undefined'.

By adding e.g. any as second generic to the useMutation 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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
jackmelliscommented, Aug 27, 2020

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

1reaction
tannerlinsleycommented, Aug 25, 2020

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 x.x.patch, and not auto-resolving versions like x.x^. Otherwise, type changes would always break your code without your consent.

With that said, type changes are handled as type: or fix: semantic changes and results in new patch versions. You can and should be manually vetting and upgrading (and consequently ensuring type safety throughout) your application when you upgrade dependencies in TypeScript.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - TypeScript 3.9
This is a breaking change, but we believe most code was written with the new interpretation in mind. Users who want to revert...
Read more >
Announcing TypeScript 2.8 - Microsoft Developer Blogs
Breaking changes · Unused type parameters are checked under --noUnusedParameters · HTMLObjectElement no longer has an alt attribute.
Read more >
GWT Release Notes
Request methods that use Collections as parameters in RequestFactory's JSON-RPC mode now properly encode Collections. Breaking Changes and Other Changes of Note.
Read more >
Changelog | Meteor API Docs
typescript was updated to 4.2.2, make sure your read the breaking changes. Meteor Version Release. meteor-tool@2.2. Update ...
Read more >
CHANGELOG - @loopback/core
BREAKING CHANGES. Node.js v8.x is now end of life. Please upgrade to version 10 and above. See https://nodejs.org/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found