@tanstack/query-core 5.34.1 → 5.35.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/build/legacy/hydration.d.cts +1 -1
  2. package/build/legacy/hydration.d.ts +1 -1
  3. package/build/legacy/index.d.cts +1 -1
  4. package/build/legacy/index.d.ts +1 -1
  5. package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
  6. package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
  7. package/build/legacy/infiniteQueryObserver.d.cts +1 -1
  8. package/build/legacy/infiniteQueryObserver.d.ts +1 -1
  9. package/build/legacy/mutation.d.cts +1 -1
  10. package/build/legacy/mutation.d.ts +1 -1
  11. package/build/legacy/mutationCache.d.cts +1 -1
  12. package/build/legacy/mutationCache.d.ts +1 -1
  13. package/build/legacy/mutationObserver.d.cts +1 -1
  14. package/build/legacy/mutationObserver.d.ts +1 -1
  15. package/build/legacy/queriesObserver.d.cts +1 -1
  16. package/build/legacy/queriesObserver.d.ts +1 -1
  17. package/build/legacy/query.d.cts +1 -1
  18. package/build/legacy/query.d.ts +1 -1
  19. package/build/legacy/queryCache.d.cts +1 -1
  20. package/build/legacy/queryCache.d.ts +1 -1
  21. package/build/legacy/queryClient.d.cts +1 -1
  22. package/build/legacy/queryClient.d.ts +1 -1
  23. package/build/legacy/queryObserver.d.cts +1 -1
  24. package/build/legacy/queryObserver.d.ts +1 -1
  25. package/build/legacy/retryer.d.cts +1 -1
  26. package/build/legacy/retryer.d.ts +1 -1
  27. package/build/legacy/{types-PcQm32IV.d.ts → types-MRM6XQm8.d.ts} +1 -1
  28. package/build/legacy/{types-eJX-7bPI.d.cts → types-bm8APd3J.d.cts} +1 -1
  29. package/build/legacy/types.cjs.map +1 -1
  30. package/build/legacy/types.d.cts +1 -1
  31. package/build/legacy/types.d.ts +1 -1
  32. package/build/legacy/utils.cjs +1 -1
  33. package/build/legacy/utils.cjs.map +1 -1
  34. package/build/legacy/utils.d.cts +1 -1
  35. package/build/legacy/utils.d.ts +1 -1
  36. package/build/legacy/utils.js +1 -1
  37. package/build/legacy/utils.js.map +1 -1
  38. package/build/modern/hydration.d.cts +1 -1
  39. package/build/modern/hydration.d.ts +1 -1
  40. package/build/modern/index.d.cts +1 -1
  41. package/build/modern/index.d.ts +1 -1
  42. package/build/modern/infiniteQueryBehavior.d.cts +1 -1
  43. package/build/modern/infiniteQueryBehavior.d.ts +1 -1
  44. package/build/modern/infiniteQueryObserver.d.cts +1 -1
  45. package/build/modern/infiniteQueryObserver.d.ts +1 -1
  46. package/build/modern/mutation.d.cts +1 -1
  47. package/build/modern/mutation.d.ts +1 -1
  48. package/build/modern/mutationCache.d.cts +1 -1
  49. package/build/modern/mutationCache.d.ts +1 -1
  50. package/build/modern/mutationObserver.d.cts +1 -1
  51. package/build/modern/mutationObserver.d.ts +1 -1
  52. package/build/modern/queriesObserver.d.cts +1 -1
  53. package/build/modern/queriesObserver.d.ts +1 -1
  54. package/build/modern/query.d.cts +1 -1
  55. package/build/modern/query.d.ts +1 -1
  56. package/build/modern/queryCache.d.cts +1 -1
  57. package/build/modern/queryCache.d.ts +1 -1
  58. package/build/modern/queryClient.d.cts +1 -1
  59. package/build/modern/queryClient.d.ts +1 -1
  60. package/build/modern/queryObserver.d.cts +1 -1
  61. package/build/modern/queryObserver.d.ts +1 -1
  62. package/build/modern/retryer.d.cts +1 -1
  63. package/build/modern/retryer.d.ts +1 -1
  64. package/build/modern/{types-PcQm32IV.d.ts → types-MRM6XQm8.d.ts} +1 -1
  65. package/build/modern/{types-eJX-7bPI.d.cts → types-bm8APd3J.d.cts} +1 -1
  66. package/build/modern/types.cjs.map +1 -1
  67. package/build/modern/types.d.cts +1 -1
  68. package/build/modern/types.d.ts +1 -1
  69. package/build/modern/utils.cjs +1 -1
  70. package/build/modern/utils.cjs.map +1 -1
  71. package/build/modern/utils.d.cts +1 -1
  72. package/build/modern/utils.d.ts +1 -1
  73. package/build/modern/utils.js +1 -1
  74. package/build/modern/utils.js.map +1 -1
  75. package/package.json +1 -1
  76. package/src/__tests__/OmitKeyof.test-d.ts +117 -1
  77. package/src/__tests__/utils.test.tsx +14 -0
  78. package/src/types.ts +5 -1
  79. package/src/utils.ts +2 -3
@@ -2,7 +2,7 @@ import { describe, expectTypeOf, it } from 'vitest'
2
2
  import type { OmitKeyof } from '..'
3
3
 
4
4
  describe('OmitKeyof', () => {
5
- it("'s type check", () => {
5
+ it("'s string key type check", () => {
6
6
  type A = {
7
7
  x: string
8
8
  y: number
@@ -56,4 +56,120 @@ describe('OmitKeyof', () => {
56
56
  >
57
57
  >().toEqualTypeOf<ExpectedType>
58
58
  })
59
+
60
+ it("'s number key type check", () => {
61
+ type A = {
62
+ [1]: string
63
+ [2]: number
64
+ }
65
+
66
+ type ExpectedType = {
67
+ [1]: string
68
+ }
69
+
70
+ // Bad point
71
+ // 1. original Omit can use 3 as type parameter with no type error
72
+ // 2. original Omit have no auto complete for 2nd type parameter
73
+ expectTypeOf<Omit<A, 3 | 2>>().toEqualTypeOf<ExpectedType>()
74
+
75
+ // Solution
76
+
77
+ // 1. strictly
78
+ expectTypeOf<
79
+ OmitKeyof<
80
+ A,
81
+ // OmitKeyof can't use 3 as type parameter with type error because A don't have key 3
82
+ // @ts-expect-error Type does not satisfy the constraint keyof A
83
+ 3 | 2
84
+ >
85
+ >().toEqualTypeOf<ExpectedType>
86
+ expectTypeOf<
87
+ OmitKeyof<
88
+ A,
89
+ // OmitKeyof can't use 3 as type parameter with type error because A don't have key 3
90
+ // @ts-expect-error Type does not satisfy the constraint keyof A
91
+ 3 | 2,
92
+ 'strictly'
93
+ >
94
+ >().toEqualTypeOf<ExpectedType>
95
+
96
+ // 2. safely
97
+ expectTypeOf<
98
+ OmitKeyof<
99
+ A,
100
+ // OmitKeyof can't use 3 as type parameter type error with strictly parameter or default parameter
101
+ // @ts-expect-error Type does not satisfy the constraint keyof A
102
+ 3 | 2
103
+ >
104
+ >().toEqualTypeOf<ExpectedType>
105
+ expectTypeOf<
106
+ OmitKeyof<
107
+ A,
108
+ // With 'safely', OmitKeyof can use 3 as type parameter like original Omit but This support autocomplete too yet for DX.
109
+ 3 | 2,
110
+ 'safely'
111
+ >
112
+ >().toEqualTypeOf<ExpectedType>
113
+ })
114
+
115
+ it("'s symbol key type check", () => {
116
+ const symbol1 = Symbol()
117
+ const symbol2 = Symbol()
118
+ const symbol3 = Symbol()
119
+
120
+ type A = {
121
+ [symbol1]: string
122
+ [symbol2]: number
123
+ }
124
+
125
+ type ExpectedType = {
126
+ [symbol1]: string
127
+ }
128
+
129
+ // Bad point
130
+ // 1. original Omit can use symbol3 as type parameter with no type error
131
+ // 2. original Omit have no auto complete for 2nd type parameter
132
+ expectTypeOf<
133
+ Omit<A, typeof symbol3 | typeof symbol2>
134
+ >().toEqualTypeOf<ExpectedType>()
135
+
136
+ // Solution
137
+
138
+ // 1. strictly
139
+ expectTypeOf<
140
+ OmitKeyof<
141
+ A,
142
+ // OmitKeyof can't use symbol3 as type parameter with type error because A don't have key symbol3
143
+ // @ts-expect-error Type does not satisfy the constraint keyof A
144
+ typeof symbol3 | typeof symbol2
145
+ >
146
+ >().toEqualTypeOf<ExpectedType>
147
+ expectTypeOf<
148
+ OmitKeyof<
149
+ A,
150
+ // OmitKeyof can't use symbol3 as type parameter with type error because A don't have key symbol3
151
+ // @ts-expect-error Type does not satisfy the constraint keyof A
152
+ typeof symbol3 | typeof symbol2,
153
+ 'strictly'
154
+ >
155
+ >().toEqualTypeOf<ExpectedType>
156
+
157
+ // 2. safely
158
+ expectTypeOf<
159
+ OmitKeyof<
160
+ A,
161
+ // OmitKeyof can't use symbol3 as type parameter type error with strictly parameter or default parameter
162
+ // @ts-expect-error Type does not satisfy the constraint keyof A
163
+ typeof symbol3 | typeof symbol2
164
+ >
165
+ >().toEqualTypeOf<ExpectedType>
166
+ expectTypeOf<
167
+ OmitKeyof<
168
+ A,
169
+ // With 'safely', OmitKeyof can use symbol3 as type parameter like original Omit but This support autocomplete too yet for DX.
170
+ typeof symbol3 | typeof symbol2,
171
+ 'safely'
172
+ >
173
+ >().toEqualTypeOf<ExpectedType>
174
+ })
59
175
  })
@@ -376,6 +376,20 @@ describe('core/utils', () => {
376
376
 
377
377
  expect(current).toBe(next)
378
378
  })
379
+
380
+ it('should return the previous value when both values are an array of undefined', () => {
381
+ const current = [undefined]
382
+ const next = replaceEqualDeep(current, [undefined])
383
+
384
+ expect(next).toBe(current)
385
+ })
386
+
387
+ it('should return the previous value when both values are an array that contains undefined', () => {
388
+ const current = [{ foo: 1 }, undefined]
389
+ const next = replaceEqualDeep(current, [{ foo: 1 }, undefined])
390
+
391
+ expect(next).toBe(current)
392
+ })
379
393
  })
380
394
 
381
395
  describe('matchMutation', () => {
package/src/types.ts CHANGED
@@ -10,7 +10,11 @@ import type { MutationCache } from './mutationCache'
10
10
  export type OmitKeyof<
11
11
  TObject,
12
12
  TKey extends TStrictly extends 'safely'
13
- ? keyof TObject | (string & Record<never, never>)
13
+ ?
14
+ | keyof TObject
15
+ | (string & Record<never, never>)
16
+ | (number & Record<never, never>)
17
+ | (symbol & Record<never, never>)
14
18
  : keyof TObject,
15
19
  TStrictly extends 'strictly' | 'safely' = 'strictly',
16
20
  > = Omit<TObject, TKey>
package/src/utils.ts CHANGED
@@ -232,10 +232,9 @@ export function replaceEqualDeep(a: any, b: any): any {
232
232
  for (let i = 0; i < bSize; i++) {
233
233
  const key = array ? i : bItems[i]
234
234
  if (
235
- !array &&
235
+ ((!array && aItems.includes(key)) || array) &&
236
236
  a[key] === undefined &&
237
- b[key] === undefined &&
238
- aItems.includes(key)
237
+ b[key] === undefined
239
238
  ) {
240
239
  copy[key] = undefined
241
240
  equalItems++