Skip to content

Commit

Permalink
refactor(query-core): improve type safety and performance in `getMuta…
Browse files Browse the repository at this point in the history
…tionDefaults` (#8669)

- Change return type to exclude mutationKey using OmitKeyof
- Replace spread operator with Object.assign for better performance

Co-authored-by: Dominik Dorfmeister <[email protected]>
  • Loading branch information
samuel871211 and TkDodo authored Mar 3, 2025
1 parent c0f27f6 commit 4d8c27b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/query-core/src/queryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,14 +605,17 @@ export class QueryClient {

getMutationDefaults(
mutationKey: MutationKey,
): MutationObserverOptions<any, any, any, any> {
): OmitKeyof<MutationObserverOptions<any, any, any, any>, 'mutationKey'> {
const defaults = [...this.#mutationDefaults.values()]

let result: MutationObserverOptions<any, any, any, any> = {}
const result: OmitKeyof<
MutationObserverOptions<any, any, any, any>,
'mutationKey'
> = {}

defaults.forEach((queryDefault) => {
if (partialMatchKey(mutationKey, queryDefault.mutationKey)) {
result = { ...result, ...queryDefault.defaultOptions }
Object.assign(result, queryDefault.defaultOptions)
}
})

Expand Down

0 comments on commit 4d8c27b

Please sign in to comment.