Skip to content
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

fix(types): enable more types for first QueryKey #577

Merged
merged 4 commits into from Jun 14, 2020
Merged

fix(types): enable more types for first QueryKey #577

merged 4 commits into from Jun 14, 2020

Conversation

CreativeTechGuy
Copy link
Contributor

@CreativeTechGuy CreativeTechGuy commented Jun 12, 2020

This change enables more types beyond just string for the first QueryKey but still ensures that it's not null/undefined.

  • The current type is too strict
  • The queryKeySerializerFn doesn't play well with TypeScript when removing the first key so TypeScript users will benefit from being able to move their string key to the end of the list instead of having to add an additional argument to their functions.

This change will enable the following TypeScript code:

function doAdd(num: number): Promise<number> {
    return Promise.resolve(num + 1);
}
useQuery<number, [number, string]>([10, "adder"], doAdd);

Before this change you'd have to modify your function to accept an additional argument which was unnecessary:

function doAdd(key: string, num: number): Promise<number>{
    return Promise.resolve(num + 1);
}
useQuery<number, [string, number]>(["adder", 10], doAdd);

@CreativeTechGuy
Copy link
Contributor Author

Updated tests file to reflect these changes

@tannerlinsley tannerlinsley merged commit 87008db into TanStack:master Jun 14, 2020
@tannerlinsley
Copy link
Collaborator

🎉 This PR is included in version 1.5.8 🎉

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.

None yet

2 participants