-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Prefer ReadonlyArray for query keys #1854
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
Conversation
Since keys are treated as readonly anway, this allows users to use `as const` without nasty surprises.
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/tannerlinsley/react-query/6VpDtXcKY8mc1vnRF1QuJpDmVtdH |
|
@tannerlinsley Do I need to do anything for this to be merged? |
|
🎉 This PR is included in version 3.12.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
* 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
Mutable arrays can be passed to functions expecting readonly arrays but readonly arrays can't be passed to functions expecting mutable arrays. Since
react-querydoesn't actually mutate query keys, it should use the more permissiveReadonlyArrayforQueryKey(andMutationKey) instead.This allows users to do things like this without having to strip
readonlyfrom the inferred types: