refactor(queryClient): accept generics on setQueryDefaults and setMutationDefaults#5983
refactor(queryClient): accept generics on setQueryDefaults and setMutationDefaults#5983DarioSiroki wants to merge 9 commits intoTanStack:rcfrom
Conversation
…ationDefaults
This change improves type inferring and improves DX.
As an example, before this PR, variables accepted by onSettled and onError would not be typed. After this PR, and thanks to v5's default Error,
the whole thing is now typed after you specify mutationFn and create a context. This means developer doesn't have to manually type cast anymore if
he is working with data, context, error or response variables inside setMutationDefaults or setQueryDefaults methods.
queryClient.setMutationDefaults(key, {
mutationFn: async (text: string) => text,
onMutate: () => {
return 1
},
onSettled: (data, error, context) => {
},
onError(error, variables, context) {
},
})
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
☁️ Nx Cloud ReportCI is running/has finished running commands for commit d8730c3. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
|
I see the cause, I'll fix it |
method signatures of setQueryDefaults and setMutationDefaults now match the core lib's signatures
…rioSiroki/query into feature/generics-on-mutation-defaults
|
there's still a build error for the vue adapter: |
Sorry, been a bit busy lately. I'd probably fix it already but I'm having difficulties with running the vue adapter which I haven't figured out yet. The workspace imports of tanstack core are broken. Is there any additional step to do besides pnpm install that I've missed? |
|
@DamianOsipiuk could you have a look maybe? |
I figured out what was the issue, I had to build query-core since vue-query imports from query-client's Still need a bit more time to check some things, I'll push a fix soon™ BTW contributing.md says "we are using pnpm v7" which wasted some of my time - I thought that the fact that I'm using v8 might be the issue. I was fighting corepack to use v7, but it kept using v8 because that's what's specified in package.json. Might wanna change that note on the contributing.md because it's outdated |
3a2da21 to
8b125c0
Compare
|
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 d8730c3:
|
Codecov ReportAll modified lines are covered by tests ✅ ❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
... and 71 files with indirect coverage changes 📢 Thoughts on this report? Let us know!. |
|
Hey @TkDodo, I saw that this PR got closed, maybe when the I’m interested in this feature and would love to help out if needed! |
This change improves type inferring and improves DX.
As an example, before this PR, onSettled and onError's parameters would not be typed/automatically inferred. After this PR, and thanks to v5's default Error, the whole thing is now typed after you specify mutationFn and create a context. This means developer doesn't have to manually type cast anymore if he is working with data, context, error or response variables inside setMutationDefaults or setQueryDefaults methods.