-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix(useQuery): make sure queryKeys are always an array at runtime when passed to the queryFn #2200
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
…n passed to the queryFn this is a regression from #2074 the real culprit we tried to fix was typings being still just TQueryKey in the FetchContext, which is not what it is at runtime, because if your QueryKey is a string, it will be [string] there. See: https://github.com/tannerlinsley/react-query/pull/2074/files#r606362656 this fix re-adds the `ensureArray` call, but makes it narrow the type (compromised type assertion) so that the FetchContext will receive an `EnsuredQueryKey`, which is always an Array
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/tannerlinsley/react-query/bzKyuUHUEkzzeKRzADxyRizq5kYQ |
| ): EnsuredQueryKey<T> { | ||
| return (Array.isArray(value) | ||
| ? value | ||
| : ([value] as unknown)) as EnsuredQueryKey<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couldn't get the type to work any other way, I think Array.isArray is not smart enough. Do you know a better way @boschni ?
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 868eee6:
|
chore: add prettier to pipeline checks and include .ts files (#2205)
# Conflicts: # src/core/types.ts
|
🎉 This PR is included in version 3.15.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
fixes #2149
this is a regression from #2074
the real culprit we tried to fix was typings being still just TQueryKey in the FetchContext, which is not what it is at runtime, because if your QueryKey is a string, it will be [string] there.
See: https://github.com/tannerlinsley/react-query/pull/2074/files#r606362656
this fix re-adds the
ensureArraycall, but makes it narrow the type (compromised type assertion) so that the FetchContext will receive anEnsuredQueryKey, which is always an Array