Skip to content

Conversation

@pluma
Copy link
Contributor

@pluma pluma commented Feb 23, 2021

Mutable arrays can be passed to functions expecting readonly arrays but readonly arrays can't be passed to functions expecting mutable arrays. Since react-query doesn't actually mutate query keys, it should use the more permissive ReadonlyArray for QueryKey (and MutationKey) instead.

This allows users to do things like this without having to strip readonly from the inferred types:

const query = [["my.query.key", "abc"], () => fetch("/my/resource")] as const

Since keys are treated as readonly anway, this allows users to use `as const` without nasty surprises.
@vercel
Copy link

vercel bot commented Feb 23, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/tannerlinsley/react-query/6VpDtXcKY8mc1vnRF1QuJpDmVtdH
✅ Preview: https://react-query-git-fork-pluma-patch-1-tannerlinsley.vercel.app

@pluma
Copy link
Contributor Author

pluma commented Mar 1, 2021

@tannerlinsley Do I need to do anything for this to be merged?

@TkDodo TkDodo merged commit f2137dc into TanStack:master Mar 2, 2021
@tannerlinsley
Copy link
Member

🎉 This PR is included in version 3.12.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

pascalduez pushed a commit to flow-typed/flow-typed that referenced this pull request Mar 23, 2021
* Infer data type from query function instead of reverse. See TanStack/query#1470
* Default generics to mixed like TypeScript does with unknown
* Use $ReadOnlyArray for query keys. See TanStack/query#1854
* Remove impossible null states (void | T instead of ?T)
* Attempt to fix infinite query types
* Export all types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants