@tanstack/query-core 4.29.11 → 4.29.14

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-core",
3
- "version": "4.29.11",
3
+ "version": "4.29.14",
4
4
  "description": "The framework agnostic core that powers TanStack Query",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -8,6 +8,8 @@ type NotifyFunction = (callback: () => void) => void
8
8
 
9
9
  type BatchNotifyFunction = (callback: () => void) => void
10
10
 
11
+ type BatchCallsCallback<T extends unknown[]> = (...args: T) => void
12
+
11
13
  export function createNotifyManager() {
12
14
  let queue: NotifyCallback[] = []
13
15
  let transactions = 0
@@ -45,12 +47,14 @@ export function createNotifyManager() {
45
47
  /**
46
48
  * All calls to the wrapped function will be batched.
47
49
  */
48
- const batchCalls = <T extends Function>(callback: T): T => {
49
- return ((...args: any[]) => {
50
+ const batchCalls = <T extends unknown[]>(
51
+ callback: BatchCallsCallback<T>,
52
+ ): BatchCallsCallback<T> => {
53
+ return (...args) => {
50
54
  schedule(() => {
51
55
  callback(...args)
52
56
  })
53
- }) as any
57
+ }
54
58
  }
55
59
 
56
60
  const flush = (): void => {
@@ -48,4 +48,19 @@ describe('notifyManager', () => {
48
48
 
49
49
  expect(notifySpy).toHaveBeenCalledTimes(1)
50
50
  })
51
+
52
+ it('typedefs should catch proper signatures', async () => {
53
+ const notifyManagerTest = createNotifyManager()
54
+
55
+ // we define some fn with its signature:
56
+ const fn: (a: string, b: number) => string = (a, b) => a + b
57
+
58
+ //now somefn expect to be called with args [a: string, b: number]
59
+ const someFn = notifyManagerTest.batchCalls(fn)
60
+
61
+ someFn('im happy', 4)
62
+
63
+ //@ts-expect-error
64
+ someFn('im not happy', false)
65
+ })
51
66
  })