Skip to content

Conversation

@TkDodo
Copy link
Collaborator

@TkDodo TkDodo commented Apr 27, 2021

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 ensureArray call, but makes it narrow the type (compromised type assertion) so that the FetchContext will receive an EnsuredQueryKey, which is always an Array

TkDodo added 4 commits April 2, 2021 21:01
…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
@vercel
Copy link

vercel bot commented Apr 27, 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/bzKyuUHUEkzzeKRzADxyRizq5kYQ
✅ Preview: https://react-query-git-fork-tkdodo-feature-2149-tannerlinsley.vercel.app

): EnsuredQueryKey<T> {
return (Array.isArray(value)
? value
: ([value] as unknown)) as EnsuredQueryKey<T>
Copy link
Collaborator Author

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 ?

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 27, 2021

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:

Sandbox Source
tannerlinsley/react-query: basic Configuration
tannerlinsley/react-query: basic-typescript Configuration

TkDodo added 3 commits April 29, 2021 21:49
chore: add prettier to pipeline checks and include .ts files (#2205)
# Conflicts:
#	src/core/types.ts
@TkDodo TkDodo merged commit 4083c1e into TanStack:master Apr 29, 2021
@TkDodo TkDodo deleted the feature/2149 branch April 29, 2021 20:17
@tannerlinsley
Copy link
Member

🎉 This PR is included in version 3.15.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

Can't pass a string value as the first parameter of useQuery()

2 participants