@tanstack/angular-query-experimental 5.103.2 → 5.104.0
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/dist/create-base-query.d.mts +168 -0
- package/dist/create-base-query.d.mts.map +1 -0
- package/dist/create-base-query.mjs +91 -0
- package/dist/create-base-query.mjs.map +1 -0
- package/dist/devtools/index.d.mts +3 -0
- package/dist/devtools/index.mjs +2 -0
- package/dist/devtools/production/index.d.mts +4 -0
- package/dist/devtools/production/index.mjs +2 -0
- package/dist/devtools/stub.d.mts +5 -0
- package/dist/devtools/stub.d.mts.map +1 -0
- package/dist/devtools/stub.mjs +9 -0
- package/dist/devtools/stub.mjs.map +1 -0
- package/dist/devtools/types.d.mts +106 -0
- package/dist/devtools/types.d.mts.map +1 -0
- package/dist/devtools/types.mjs +1 -0
- package/{devtools/with-devtools.d.ts → dist/devtools/with-devtools.d.mts} +4 -1
- package/dist/devtools/with-devtools.d.mts.map +1 -0
- package/dist/devtools/with-devtools.mjs +110 -0
- package/dist/devtools/with-devtools.mjs.map +1 -0
- package/dist/devtools-panel/index.d.mts +3 -0
- package/dist/devtools-panel/index.mjs +2 -0
- package/{devtools-panel/inject-devtools-panel.d.ts → dist/devtools-panel/inject-devtools-panel.d.mts} +4 -1
- package/dist/devtools-panel/inject-devtools-panel.d.mts.map +1 -0
- package/dist/devtools-panel/inject-devtools-panel.mjs +67 -0
- package/dist/devtools-panel/inject-devtools-panel.mjs.map +1 -0
- package/dist/devtools-panel/production/index.d.mts +4 -0
- package/dist/devtools-panel/production/index.mjs +2 -0
- package/dist/devtools-panel/stub.d.mts +5 -0
- package/dist/devtools-panel/stub.d.mts.map +1 -0
- package/dist/devtools-panel/stub.mjs +7 -0
- package/dist/devtools-panel/stub.mjs.map +1 -0
- package/dist/devtools-panel/types.d.mts +51 -0
- package/dist/devtools-panel/types.d.mts.map +1 -0
- package/dist/devtools-panel/types.mjs +1 -0
- package/dist/index.d.mts +16 -0
- package/{index.mjs → dist/index.mjs} +8 -21
- package/dist/index.mjs.map +1 -0
- package/{infinite-query-options.d.ts → dist/infinite-query-options.d.mts} +28 -25
- package/dist/infinite-query-options.d.mts.map +1 -0
- package/dist/infinite-query-options.mjs +8 -0
- package/dist/infinite-query-options.mjs.map +1 -0
- package/{inject-infinite-query.d.ts → dist/inject-infinite-query.d.mts} +13 -10
- package/dist/inject-infinite-query.d.mts.map +1 -0
- package/dist/inject-infinite-query.mjs +13 -0
- package/dist/inject-infinite-query.mjs.map +1 -0
- package/{inject-is-fetching.d.ts → dist/inject-is-fetching.d.mts} +11 -8
- package/dist/inject-is-fetching.d.mts.map +1 -0
- package/dist/inject-is-fetching.mjs +69 -0
- package/dist/inject-is-fetching.mjs.map +1 -0
- package/{inject-is-mutating.d.ts → dist/inject-is-mutating.d.mts} +11 -8
- package/dist/inject-is-mutating.d.mts.map +1 -0
- package/dist/inject-is-mutating.mjs +52 -0
- package/dist/inject-is-mutating.mjs.map +1 -0
- package/{inject-is-restoring.d.ts → dist/inject-is-restoring.d.mts} +10 -8
- package/dist/inject-is-restoring.d.mts.map +1 -0
- package/dist/inject-is-restoring.mjs +35 -0
- package/dist/inject-is-restoring.mjs.map +1 -0
- package/{inject-mutation-state.d.ts → dist/inject-mutation-state.d.mts} +13 -11
- package/dist/inject-mutation-state.d.mts.map +1 -0
- package/dist/inject-mutation-state.mjs +103 -0
- package/dist/inject-mutation-state.mjs.map +1 -0
- package/{inject-mutation.d.ts → dist/inject-mutation.d.mts} +12 -9
- package/dist/inject-mutation.d.mts.map +1 -0
- package/dist/inject-mutation.mjs +226 -0
- package/dist/inject-mutation.mjs.map +1 -0
- package/dist/inject-queries-experimental/index.d.mts +2 -0
- package/dist/inject-queries-experimental/index.mjs +2 -0
- package/{inject-queries.d.ts → dist/inject-queries.d.mts} +33 -53
- package/dist/inject-queries.d.mts.map +1 -0
- package/dist/inject-queries.mjs +203 -0
- package/dist/inject-queries.mjs.map +1 -0
- package/{inject-query-client.d.ts → dist/inject-query-client.d.mts} +6 -3
- package/dist/inject-query-client.d.mts.map +1 -0
- package/dist/inject-query-client.mjs +23 -0
- package/dist/inject-query-client.mjs.map +1 -0
- package/{inject-query.d.ts → dist/inject-query.d.mts} +13 -10
- package/dist/inject-query.d.mts.map +1 -0
- package/dist/inject-query.mjs +12 -0
- package/dist/inject-query.mjs.map +1 -0
- package/{mutation-options.d.ts → dist/mutation-options.d.mts} +5 -2
- package/dist/mutation-options.d.mts.map +1 -0
- package/dist/mutation-options.mjs +8 -0
- package/dist/mutation-options.mjs.map +1 -0
- package/dist/pending-tasks-compat.d.mts +9 -0
- package/dist/pending-tasks-compat.d.mts.map +1 -0
- package/dist/pending-tasks-compat.mjs +13 -0
- package/dist/pending-tasks-compat.mjs.map +1 -0
- package/{providers.d.ts → dist/providers.d.mts} +7 -5
- package/dist/providers.d.mts.map +1 -0
- package/dist/providers.mjs +124 -0
- package/dist/providers.mjs.map +1 -0
- package/{query-options.d.ts → dist/query-options.d.mts} +34 -31
- package/dist/query-options.d.mts.map +1 -0
- package/dist/query-options.mjs +8 -0
- package/dist/query-options.mjs.map +1 -0
- package/{signal-proxy.d.ts → dist/signal-proxy.d.mts} +5 -4
- package/dist/signal-proxy.d.mts.map +1 -0
- package/dist/signal-proxy.mjs +35 -0
- package/dist/signal-proxy.mjs.map +1 -0
- package/{types.d.ts → dist/types.d.mts} +24 -26
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +6 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +50 -20
- package/src/__tests__/infinite-query-options.test-d.ts +314 -0
- package/src/__tests__/infinite-query-options.test.ts +19 -0
- package/src/__tests__/inject-devtools-panel.test.ts +196 -0
- package/src/__tests__/inject-infinite-query.test-d.ts +66 -0
- package/src/__tests__/inject-infinite-query.test.ts +227 -0
- package/src/__tests__/inject-is-fetching.test.ts +108 -0
- package/src/__tests__/inject-is-mutating.test.ts +113 -0
- package/src/__tests__/inject-is-restoring.test.ts +93 -0
- package/src/__tests__/inject-mutation-state.test-d.ts +22 -0
- package/src/__tests__/inject-mutation-state.test.ts +198 -0
- package/src/__tests__/inject-mutation.test-d.ts +158 -0
- package/src/__tests__/inject-mutation.test.ts +1161 -0
- package/src/__tests__/inject-queries.test-d.ts +196 -0
- package/src/__tests__/inject-queries.test.ts +240 -0
- package/src/__tests__/inject-query.test-d.ts +357 -0
- package/src/__tests__/inject-query.test.ts +700 -0
- package/src/__tests__/mutation-options.test-d.ts +234 -0
- package/src/__tests__/mutation-options.test.ts +344 -0
- package/src/__tests__/pending-tasks.test.ts +644 -0
- package/src/__tests__/provide-query-client.test.ts +38 -0
- package/src/__tests__/provide-tanstack-query.test.ts +38 -0
- package/src/__tests__/query-options.test-d.ts +262 -0
- package/src/__tests__/query-options.test.ts +14 -0
- package/src/__tests__/signal-proxy.test.ts +27 -0
- package/src/__tests__/test-utils.ts +77 -0
- package/src/__tests__/with-devtools.test.ts +674 -0
- package/src/create-base-query.ts +176 -0
- package/src/devtools/index.ts +8 -0
- package/src/devtools/production/index.ts +1 -0
- package/src/devtools/stub.ts +7 -0
- package/src/devtools/types.ts +116 -0
- package/src/devtools/with-devtools.ts +182 -0
- package/src/devtools-panel/index.ts +8 -0
- package/src/devtools-panel/inject-devtools-panel.ts +110 -0
- package/src/devtools-panel/production/index.ts +1 -0
- package/src/devtools-panel/stub.ts +7 -0
- package/src/devtools-panel/types.ts +57 -0
- package/src/index.ts +60 -0
- package/src/infinite-query-options.ts +354 -0
- package/src/inject-infinite-query.ts +296 -0
- package/src/inject-is-fetching.ts +97 -0
- package/src/inject-is-mutating.ts +80 -0
- package/src/inject-is-restoring.ts +53 -0
- package/src/inject-mutation-state.ts +167 -0
- package/src/inject-mutation.ts +328 -0
- package/src/inject-queries-experimental/index.ts +1 -0
- package/src/inject-queries.ts +480 -0
- package/src/inject-query-client.ts +22 -0
- package/src/inject-query.ts +208 -0
- package/src/mutation-options.ts +121 -0
- package/src/pending-tasks-compat.ts +27 -0
- package/src/providers.ts +170 -0
- package/src/query-options.ts +292 -0
- package/src/signal-proxy.ts +46 -0
- package/src/types.ts +429 -0
- package/create-base-query.d.ts +0 -164
- package/create-base-query.mjs +0 -99
- package/create-base-query.mjs.map +0 -1
- package/devtools/index.d.ts +0 -2
- package/devtools/index.mjs +0 -5
- package/devtools/index.mjs.map +0 -1
- package/devtools/production/index.d.ts +0 -1
- package/devtools/stub.d.ts +0 -2
- package/devtools/stub.mjs +0 -8
- package/devtools/stub.mjs.map +0 -1
- package/devtools/types.d.ts +0 -103
- package/devtools/with-devtools.mjs +0 -106
- package/devtools/with-devtools.mjs.map +0 -1
- package/devtools-panel/index.d.ts +0 -2
- package/devtools-panel/index.mjs +0 -5
- package/devtools-panel/index.mjs.map +0 -1
- package/devtools-panel/inject-devtools-panel.mjs +0 -72
- package/devtools-panel/inject-devtools-panel.mjs.map +0 -1
- package/devtools-panel/production/index.d.ts +0 -1
- package/devtools-panel/stub.d.ts +0 -2
- package/devtools-panel/stub.mjs +0 -8
- package/devtools-panel/stub.mjs.map +0 -1
- package/devtools-panel/types.d.ts +0 -48
- package/index.d.ts +0 -25
- package/index.mjs.map +0 -1
- package/infinite-query-options.mjs +0 -7
- package/infinite-query-options.mjs.map +0 -1
- package/inject-infinite-query.mjs +0 -18
- package/inject-infinite-query.mjs.map +0 -1
- package/inject-is-fetching.mjs +0 -31
- package/inject-is-fetching.mjs.map +0 -1
- package/inject-is-mutating.mjs +0 -31
- package/inject-is-mutating.mjs.map +0 -1
- package/inject-is-restoring.mjs +0 -21
- package/inject-is-restoring.mjs.map +0 -1
- package/inject-mutation-state.mjs +0 -51
- package/inject-mutation-state.mjs.map +0 -1
- package/inject-mutation.mjs +0 -94
- package/inject-mutation.mjs.map +0 -1
- package/inject-queries-experimental/index.d.ts +0 -1
- package/inject-queries-experimental/index.mjs +0 -5
- package/inject-queries-experimental/index.mjs.map +0 -1
- package/inject-queries.mjs +0 -82
- package/inject-queries.mjs.map +0 -1
- package/inject-query-client.mjs +0 -9
- package/inject-query-client.mjs.map +0 -1
- package/inject-query.mjs +0 -14
- package/inject-query.mjs.map +0 -1
- package/mutation-options.mjs +0 -7
- package/mutation-options.mjs.map +0 -1
- package/pending-tasks-compat.d.ts +0 -7
- package/pending-tasks-compat.mjs +0 -19
- package/pending-tasks-compat.mjs.map +0 -1
- package/providers.mjs +0 -32
- package/providers.mjs.map +0 -1
- package/query-options.mjs +0 -7
- package/query-options.mjs.map +0 -1
- package/signal-proxy.mjs +0 -29
- package/signal-proxy.mjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/angular-query-experimental",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.104.0",
|
|
4
4
|
"description": "Signals for managing, caching and syncing asynchronous and remote data in Angular",
|
|
5
5
|
"author": "Arnoud de Vries",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,47 +27,77 @@
|
|
|
27
27
|
"tanstack"
|
|
28
28
|
],
|
|
29
29
|
"type": "module",
|
|
30
|
-
"types": "
|
|
31
|
-
"module": "
|
|
30
|
+
"types": "dist/index.d.mts",
|
|
31
|
+
"module": "dist/index.mjs",
|
|
32
32
|
"exports": {
|
|
33
33
|
".": {
|
|
34
34
|
"@tanstack/custom-condition": "./src/index.ts",
|
|
35
|
-
"types": "./index.d.
|
|
36
|
-
"default": "./index.mjs"
|
|
35
|
+
"types": "./dist/index.d.mts",
|
|
36
|
+
"default": "./dist/index.mjs"
|
|
37
37
|
},
|
|
38
|
-
"./package.json": "./package.json",
|
|
39
38
|
"./inject-queries-experimental": {
|
|
40
|
-
"types": "./inject-queries-experimental/index.d.
|
|
41
|
-
"default": "./inject-queries-experimental/index.mjs"
|
|
39
|
+
"types": "./dist/inject-queries-experimental/index.d.mts",
|
|
40
|
+
"default": "./dist/inject-queries-experimental/index.mjs"
|
|
42
41
|
},
|
|
43
42
|
"./devtools": {
|
|
44
|
-
"types": "./devtools/index.d.
|
|
45
|
-
"development": "./devtools/index.mjs",
|
|
46
|
-
"default": "./devtools/stub.mjs"
|
|
43
|
+
"types": "./dist/devtools/index.d.mts",
|
|
44
|
+
"development": "./dist/devtools/index.mjs",
|
|
45
|
+
"default": "./dist/devtools/stub.mjs"
|
|
47
46
|
},
|
|
48
47
|
"./devtools/production": {
|
|
49
|
-
"types": "./devtools/production/index.d.
|
|
50
|
-
"default": "./devtools/index.mjs"
|
|
48
|
+
"types": "./dist/devtools/production/index.d.mts",
|
|
49
|
+
"default": "./dist/devtools/index.mjs"
|
|
51
50
|
},
|
|
52
51
|
"./devtools-panel": {
|
|
53
|
-
"types": "./devtools-panel/index.d.
|
|
54
|
-
"development": "./devtools-panel/index.mjs",
|
|
55
|
-
"default": "./devtools-panel/stub.mjs"
|
|
52
|
+
"types": "./dist/devtools-panel/index.d.mts",
|
|
53
|
+
"development": "./dist/devtools-panel/index.mjs",
|
|
54
|
+
"default": "./dist/devtools-panel/stub.mjs"
|
|
56
55
|
},
|
|
57
56
|
"./devtools-panel/production": {
|
|
58
|
-
"types": "./devtools-panel/production/index.d.
|
|
59
|
-
"default": "./devtools-panel/index.mjs"
|
|
57
|
+
"types": "./dist/devtools-panel/production/index.d.mts",
|
|
58
|
+
"default": "./dist/devtools-panel/index.mjs"
|
|
60
59
|
}
|
|
61
60
|
},
|
|
62
61
|
"sideEffects": false,
|
|
62
|
+
"files": [
|
|
63
|
+
"dist",
|
|
64
|
+
"src"
|
|
65
|
+
],
|
|
63
66
|
"dependencies": {
|
|
64
|
-
"@tanstack/query-core": "5.
|
|
67
|
+
"@tanstack/query-core": "5.104.0"
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@analogjs/vite-plugin-angular": "^2.7.5",
|
|
71
|
+
"@angular/common": "^20.0.0",
|
|
72
|
+
"@angular/compiler": "^20.0.0",
|
|
73
|
+
"@angular/core": "^20.0.0",
|
|
74
|
+
"@angular/platform-browser": "^20.0.0",
|
|
75
|
+
"@oxc-project/runtime": "^0.151.0",
|
|
76
|
+
"@tanstack/query-test-utils": "0.0.0",
|
|
77
|
+
"@testing-library/angular": "^18.0.0",
|
|
78
|
+
"npm-run-all2": "^9.0.3",
|
|
79
|
+
"rxjs": "^7.8.2"
|
|
65
80
|
},
|
|
66
81
|
"optionalDependencies": {
|
|
67
|
-
"@tanstack/query-devtools": "5.
|
|
82
|
+
"@tanstack/query-devtools": "5.104.0"
|
|
68
83
|
},
|
|
69
84
|
"peerDependencies": {
|
|
70
85
|
"@angular/common": ">=16.0.0",
|
|
71
86
|
"@angular/core": ">=16.0.0"
|
|
87
|
+
},
|
|
88
|
+
"scripts": {
|
|
89
|
+
"clean": "premove ./dist ./coverage ./dist-ts ./.cache/test-types",
|
|
90
|
+
"compile": "tsc --project tsconfig.json",
|
|
91
|
+
"test:eslint": "eslint --concurrency=auto ./src",
|
|
92
|
+
"test:types": "npm-run-all --serial test:types:*",
|
|
93
|
+
"test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --project tsconfig.json --outDir .cache/test-types/ts56 --tsBuildInfoFile .cache/test-types/ts56.tsbuildinfo",
|
|
94
|
+
"test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --project tsconfig.json --outDir .cache/test-types/ts57 --tsBuildInfoFile .cache/test-types/ts57.tsbuildinfo",
|
|
95
|
+
"test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js --project tsconfig.json --outDir .cache/test-types/ts58 --tsBuildInfoFile .cache/test-types/ts58.tsbuildinfo",
|
|
96
|
+
"test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js --project tsconfig.json --outDir .cache/test-types/ts59 --tsBuildInfoFile .cache/test-types/ts59.tsbuildinfo",
|
|
97
|
+
"test:types:tscurrent": "tsc --project tsconfig.json --outDir .cache/test-types/tscurrent --tsBuildInfoFile .cache/test-types/tscurrent.tsbuildinfo",
|
|
98
|
+
"test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --project tsconfig.json --outDir .cache/test-types/ts70 --tsBuildInfoFile .cache/test-types/ts70.tsbuildinfo",
|
|
99
|
+
"test:lib": "vitest",
|
|
100
|
+
"test:lib:dev": "pnpm run test:lib --watch",
|
|
101
|
+
"build": "tsdown --tsconfig tsconfig.prod.json"
|
|
72
102
|
}
|
|
73
103
|
}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { assertType, describe, expectTypeOf, it } from 'vitest'
|
|
2
|
+
import { queryKey } from '@tanstack/query-test-utils'
|
|
3
|
+
import { QueryClient, dataTagSymbol, skipToken } from '@tanstack/query-core'
|
|
4
|
+
import { infiniteQueryOptions } from '../infinite-query-options'
|
|
5
|
+
import { injectInfiniteQuery } from '../inject-infinite-query'
|
|
6
|
+
import { injectQuery } from '../inject-query'
|
|
7
|
+
import type {
|
|
8
|
+
DataTag,
|
|
9
|
+
InfiniteData,
|
|
10
|
+
InitialDataFunction,
|
|
11
|
+
} from '@tanstack/query-core'
|
|
12
|
+
|
|
13
|
+
// Regression test for exported infiniteQueryOptions inference under declaration emit.
|
|
14
|
+
// TypeScript should be able to name the return type without expanding the
|
|
15
|
+
// internal data tag symbols into the consumer's .d.ts output.
|
|
16
|
+
export const exportedInfiniteQueryOptions = infiniteQueryOptions({
|
|
17
|
+
queryKey: ['invalid'],
|
|
18
|
+
getNextPageParam: () => 1,
|
|
19
|
+
initialPageParam: 1,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
describe('infiniteQueryOptions', () => {
|
|
23
|
+
it('should not allow excess properties', () => {
|
|
24
|
+
const key = queryKey()
|
|
25
|
+
assertType(
|
|
26
|
+
infiniteQueryOptions({
|
|
27
|
+
queryKey: key,
|
|
28
|
+
queryFn: () => Promise.resolve('data'),
|
|
29
|
+
getNextPageParam: () => 1,
|
|
30
|
+
initialPageParam: 1,
|
|
31
|
+
// @ts-expect-error this is a good error, because stallTime does not exist!
|
|
32
|
+
stallTime: 1000,
|
|
33
|
+
}),
|
|
34
|
+
)
|
|
35
|
+
})
|
|
36
|
+
it('should infer types for callbacks', () => {
|
|
37
|
+
const key = queryKey()
|
|
38
|
+
infiniteQueryOptions({
|
|
39
|
+
queryKey: key,
|
|
40
|
+
queryFn: () => Promise.resolve('data'),
|
|
41
|
+
staleTime: 1000,
|
|
42
|
+
getNextPageParam: () => 1,
|
|
43
|
+
initialPageParam: 1,
|
|
44
|
+
select: (data) => {
|
|
45
|
+
expectTypeOf(data).toEqualTypeOf<InfiniteData<string, number>>()
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
it('should work when passed to useInfiniteQuery', () => {
|
|
50
|
+
const key = queryKey()
|
|
51
|
+
const options = infiniteQueryOptions({
|
|
52
|
+
queryKey: key,
|
|
53
|
+
queryFn: () => Promise.resolve('string'),
|
|
54
|
+
getNextPageParam: () => 1,
|
|
55
|
+
initialPageParam: 1,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const { data } = injectInfiniteQuery(() => options)
|
|
59
|
+
|
|
60
|
+
// known issue: type of pageParams is unknown when returned from useInfiniteQuery
|
|
61
|
+
expectTypeOf(data()).toEqualTypeOf<
|
|
62
|
+
InfiniteData<string, unknown> | undefined
|
|
63
|
+
>()
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('should work when passed to fetchInfiniteQuery', async () => {
|
|
67
|
+
const key = queryKey()
|
|
68
|
+
const options = infiniteQueryOptions({
|
|
69
|
+
queryKey: key,
|
|
70
|
+
queryFn: () => Promise.resolve('string'),
|
|
71
|
+
getNextPageParam: () => 1,
|
|
72
|
+
initialPageParam: 1,
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
// eslint-disable-next-line no-restricted-syntax -- grandfathered direct test
|
|
76
|
+
const data = await new QueryClient().fetchInfiniteQuery(options)
|
|
77
|
+
|
|
78
|
+
expectTypeOf(data).toEqualTypeOf<InfiniteData<string, number>>()
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('should work when passed to infiniteQuery', async () => {
|
|
82
|
+
const options = infiniteQueryOptions({
|
|
83
|
+
queryKey: ['key'],
|
|
84
|
+
queryFn: () => Promise.resolve('string'),
|
|
85
|
+
getNextPageParam: () => 1,
|
|
86
|
+
initialPageParam: 1,
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
const data = await new QueryClient().infiniteQuery(options)
|
|
90
|
+
|
|
91
|
+
expectTypeOf(data).toEqualTypeOf<InfiniteData<string, number>>()
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('should work when passed to infiniteQuery with select', async () => {
|
|
95
|
+
const options = infiniteQueryOptions({
|
|
96
|
+
queryKey: ['key'],
|
|
97
|
+
queryFn: () => Promise.resolve('string'),
|
|
98
|
+
getNextPageParam: () => 1,
|
|
99
|
+
initialPageParam: 1,
|
|
100
|
+
select: (data) => data.pages,
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
const data = await new QueryClient().infiniteQuery(options)
|
|
104
|
+
|
|
105
|
+
expectTypeOf(data).toEqualTypeOf<Array<string>>()
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('should work when passed to infiniteQuery with enabled: false', async () => {
|
|
109
|
+
const options = infiniteQueryOptions({
|
|
110
|
+
queryKey: ['key'],
|
|
111
|
+
queryFn: () => Promise.resolve('string'),
|
|
112
|
+
getNextPageParam: () => 1,
|
|
113
|
+
initialPageParam: 1,
|
|
114
|
+
enabled: false,
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
const data = await new QueryClient().infiniteQuery(options)
|
|
118
|
+
|
|
119
|
+
expectTypeOf(data).toEqualTypeOf<InfiniteData<string, number>>()
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('should work when passed to infiniteQuery with skipToken', async () => {
|
|
123
|
+
const options = infiniteQueryOptions({
|
|
124
|
+
queryKey: ['key'],
|
|
125
|
+
queryFn: skipToken,
|
|
126
|
+
getNextPageParam: () => 1,
|
|
127
|
+
initialPageParam: 1,
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
const data = await new QueryClient().infiniteQuery(options)
|
|
131
|
+
|
|
132
|
+
expectTypeOf(data).toEqualTypeOf<InfiniteData<unknown, number>>()
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
it('should tag the queryKey with the result type of the QueryFn', () => {
|
|
136
|
+
const key = queryKey()
|
|
137
|
+
const { queryKey: tagged } = infiniteQueryOptions({
|
|
138
|
+
queryKey: key,
|
|
139
|
+
queryFn: () => Promise.resolve('string'),
|
|
140
|
+
getNextPageParam: () => 1,
|
|
141
|
+
initialPageParam: 1,
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
expectTypeOf(tagged[dataTagSymbol]).toEqualTypeOf<InfiniteData<string>>()
|
|
145
|
+
})
|
|
146
|
+
it('should tag the queryKey even if no promise is returned', () => {
|
|
147
|
+
const key = queryKey()
|
|
148
|
+
const { queryKey: tagged } = infiniteQueryOptions({
|
|
149
|
+
queryKey: key,
|
|
150
|
+
queryFn: () => 'string',
|
|
151
|
+
getNextPageParam: () => 1,
|
|
152
|
+
initialPageParam: 1,
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
expectTypeOf(tagged[dataTagSymbol]).toEqualTypeOf<InfiniteData<string>>()
|
|
156
|
+
})
|
|
157
|
+
it('should tag the queryKey with the result type of the QueryFn if select is used', () => {
|
|
158
|
+
const key = queryKey()
|
|
159
|
+
const { queryKey: tagged } = infiniteQueryOptions({
|
|
160
|
+
queryKey: key,
|
|
161
|
+
queryFn: () => Promise.resolve('string'),
|
|
162
|
+
select: (data) => data.pages,
|
|
163
|
+
getNextPageParam: () => 1,
|
|
164
|
+
initialPageParam: 1,
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
expectTypeOf(tagged[dataTagSymbol]).toEqualTypeOf<InfiniteData<string>>()
|
|
168
|
+
})
|
|
169
|
+
it('should return the proper type when passed to getQueryData', () => {
|
|
170
|
+
const key = queryKey()
|
|
171
|
+
const { queryKey: tagged } = infiniteQueryOptions({
|
|
172
|
+
queryKey: key,
|
|
173
|
+
queryFn: () => Promise.resolve('string'),
|
|
174
|
+
getNextPageParam: () => 1,
|
|
175
|
+
initialPageParam: 1,
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
const queryClient = new QueryClient()
|
|
179
|
+
const data = queryClient.getQueryData(tagged)
|
|
180
|
+
|
|
181
|
+
expectTypeOf(data).toEqualTypeOf<
|
|
182
|
+
InfiniteData<string, unknown> | undefined
|
|
183
|
+
>()
|
|
184
|
+
})
|
|
185
|
+
it('should properly type when passed to setQueryData', () => {
|
|
186
|
+
const key = queryKey()
|
|
187
|
+
const { queryKey: tagged } = infiniteQueryOptions({
|
|
188
|
+
queryKey: key,
|
|
189
|
+
queryFn: () => Promise.resolve('string'),
|
|
190
|
+
getNextPageParam: () => 1,
|
|
191
|
+
initialPageParam: 1,
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
const queryClient = new QueryClient()
|
|
195
|
+
const data = queryClient.setQueryData(tagged, (prev) => {
|
|
196
|
+
expectTypeOf(prev).toEqualTypeOf<
|
|
197
|
+
InfiniteData<string, unknown> | undefined
|
|
198
|
+
>()
|
|
199
|
+
return prev
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
expectTypeOf(data).toEqualTypeOf<
|
|
203
|
+
InfiniteData<string, unknown> | undefined
|
|
204
|
+
>()
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
it('should not be allowed to be passed to non-infinite query functions', () => {
|
|
208
|
+
const key = queryKey()
|
|
209
|
+
const queryClient = new QueryClient()
|
|
210
|
+
const options = infiniteQueryOptions({
|
|
211
|
+
queryKey: key,
|
|
212
|
+
queryFn: () => Promise.resolve('string'),
|
|
213
|
+
getNextPageParam: () => 1,
|
|
214
|
+
initialPageParam: 1,
|
|
215
|
+
})
|
|
216
|
+
assertType(
|
|
217
|
+
// @ts-expect-error cannot pass infinite options to non-infinite query functions
|
|
218
|
+
injectQuery(() => options),
|
|
219
|
+
)
|
|
220
|
+
assertType(
|
|
221
|
+
// @ts-expect-error cannot pass infinite options to non-infinite query functions
|
|
222
|
+
queryClient.query(options),
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
// deprecated methods below to be removed next major version
|
|
226
|
+
assertType(
|
|
227
|
+
// @ts-expect-error cannot pass infinite options to non-infinite query functions
|
|
228
|
+
// eslint-disable-next-line no-restricted-syntax -- grandfathered direct test
|
|
229
|
+
queryClient.ensureQueryData(options),
|
|
230
|
+
)
|
|
231
|
+
assertType(
|
|
232
|
+
// @ts-expect-error cannot pass infinite options to non-infinite query functions
|
|
233
|
+
// eslint-disable-next-line no-restricted-syntax -- grandfathered direct test
|
|
234
|
+
queryClient.fetchQuery(options),
|
|
235
|
+
)
|
|
236
|
+
assertType(
|
|
237
|
+
// @ts-expect-error cannot pass infinite options to non-infinite query functions
|
|
238
|
+
// eslint-disable-next-line no-restricted-syntax -- grandfathered direct test
|
|
239
|
+
queryClient.prefetchQuery(options),
|
|
240
|
+
)
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
it('should allow optional initialData function', () => {
|
|
244
|
+
const key = queryKey()
|
|
245
|
+
const initialData: { example: boolean } | undefined = { example: true }
|
|
246
|
+
const queryOptions = infiniteQueryOptions({
|
|
247
|
+
queryKey: key,
|
|
248
|
+
queryFn: () => initialData,
|
|
249
|
+
initialData: initialData
|
|
250
|
+
? () => ({ pages: [initialData], pageParams: [] })
|
|
251
|
+
: undefined,
|
|
252
|
+
getNextPageParam: () => 1,
|
|
253
|
+
initialPageParam: 1,
|
|
254
|
+
})
|
|
255
|
+
expectTypeOf(queryOptions.initialData).toExtend<
|
|
256
|
+
| InitialDataFunction<InfiniteData<{ example: boolean }, number>>
|
|
257
|
+
| InfiniteData<{ example: boolean }, number>
|
|
258
|
+
| undefined
|
|
259
|
+
>()
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
it('should allow optional initialData object', () => {
|
|
263
|
+
const key = queryKey()
|
|
264
|
+
const initialData: { example: boolean } | undefined = { example: true }
|
|
265
|
+
const queryOptions = infiniteQueryOptions({
|
|
266
|
+
queryKey: key,
|
|
267
|
+
queryFn: () => initialData,
|
|
268
|
+
initialData: initialData
|
|
269
|
+
? { pages: [initialData], pageParams: [] }
|
|
270
|
+
: undefined,
|
|
271
|
+
getNextPageParam: () => 1,
|
|
272
|
+
initialPageParam: 1,
|
|
273
|
+
})
|
|
274
|
+
expectTypeOf(queryOptions.initialData).toExtend<
|
|
275
|
+
| InitialDataFunction<InfiniteData<{ example: boolean }, number>>
|
|
276
|
+
| InfiniteData<{ example: boolean }, number>
|
|
277
|
+
| undefined
|
|
278
|
+
>()
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
it('should return a custom query key type', () => {
|
|
282
|
+
type MyQueryKey = [Array<string>, { type: 'foo' }]
|
|
283
|
+
|
|
284
|
+
const options = infiniteQueryOptions({
|
|
285
|
+
queryKey: [['key'], { type: 'foo' }] as MyQueryKey,
|
|
286
|
+
queryFn: () => Promise.resolve(1),
|
|
287
|
+
getNextPageParam: () => 1,
|
|
288
|
+
initialPageParam: 1,
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
expectTypeOf(options.queryKey).toEqualTypeOf<
|
|
292
|
+
DataTag<MyQueryKey, InfiniteData<number>, Error>
|
|
293
|
+
>()
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
it('should return a custom query key type with datatag', () => {
|
|
297
|
+
type MyQueryKey = DataTag<
|
|
298
|
+
[Array<string>, { type: 'foo' }],
|
|
299
|
+
number,
|
|
300
|
+
Error & { myMessage: string }
|
|
301
|
+
>
|
|
302
|
+
|
|
303
|
+
const options = infiniteQueryOptions({
|
|
304
|
+
queryKey: [['key'], { type: 'foo' }] as MyQueryKey,
|
|
305
|
+
queryFn: () => Promise.resolve(1),
|
|
306
|
+
getNextPageParam: () => 1,
|
|
307
|
+
initialPageParam: 1,
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
expectTypeOf(options.queryKey).toEqualTypeOf<
|
|
311
|
+
DataTag<MyQueryKey, InfiniteData<number>, Error & { myMessage: string }>
|
|
312
|
+
>()
|
|
313
|
+
})
|
|
314
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { queryKey } from '@tanstack/query-test-utils'
|
|
3
|
+
|
|
4
|
+
import { infiniteQueryOptions } from '../infinite-query-options'
|
|
5
|
+
import type { CreateInfiniteQueryOptions } from '../types'
|
|
6
|
+
|
|
7
|
+
describe('infiniteQueryOptions', () => {
|
|
8
|
+
it('should return the object received as a parameter without any modification.', () => {
|
|
9
|
+
const key = queryKey()
|
|
10
|
+
const object: CreateInfiniteQueryOptions = {
|
|
11
|
+
queryKey: key,
|
|
12
|
+
queryFn: () => Promise.resolve(5),
|
|
13
|
+
getNextPageParam: () => null,
|
|
14
|
+
initialPageParam: null,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
expect(infiniteQueryOptions(object)).toBe(object)
|
|
18
|
+
})
|
|
19
|
+
})
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ElementRef,
|
|
3
|
+
provideZonelessChangeDetection,
|
|
4
|
+
signal,
|
|
5
|
+
} from '@angular/core'
|
|
6
|
+
import { TestBed } from '@angular/core/testing'
|
|
7
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
8
|
+
import { QueryClient } from '@tanstack/query-core'
|
|
9
|
+
import { provideTanStackQuery } from '../providers'
|
|
10
|
+
import { injectDevtoolsPanel } from '../devtools-panel'
|
|
11
|
+
|
|
12
|
+
const mockDevtoolsPanelInstance = {
|
|
13
|
+
mount: vi.fn(),
|
|
14
|
+
unmount: vi.fn(),
|
|
15
|
+
setClient: vi.fn(),
|
|
16
|
+
setErrorTypes: vi.fn(),
|
|
17
|
+
setOnClose: vi.fn(),
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const mocks = vi.hoisted(() => {
|
|
21
|
+
function MockTanstackQueryDevtoolsPanel() {
|
|
22
|
+
return mockDevtoolsPanelInstance
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
mockTanstackQueryDevtoolsPanel: vi.fn(MockTanstackQueryDevtoolsPanel),
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
vi.mock('@tanstack/query-devtools', () => ({
|
|
31
|
+
TanstackQueryDevtoolsPanel: mocks.mockTanstackQueryDevtoolsPanel,
|
|
32
|
+
}))
|
|
33
|
+
|
|
34
|
+
describe('injectDevtoolsPanel', () => {
|
|
35
|
+
let queryClient: QueryClient
|
|
36
|
+
let mockElementRef: ElementRef
|
|
37
|
+
|
|
38
|
+
const waitForDevtoolsToBeCreated = async () => {
|
|
39
|
+
await vi.waitFor(() => {
|
|
40
|
+
expect(mocks.mockTanstackQueryDevtoolsPanel).toHaveBeenCalledTimes(1)
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
beforeEach(() => {
|
|
45
|
+
vi.clearAllMocks()
|
|
46
|
+
queryClient = new QueryClient()
|
|
47
|
+
mockElementRef = new ElementRef(document.createElement('div'))
|
|
48
|
+
TestBed.configureTestingModule({
|
|
49
|
+
providers: [
|
|
50
|
+
provideZonelessChangeDetection(),
|
|
51
|
+
provideTanStackQuery(queryClient),
|
|
52
|
+
{ provide: ElementRef, useValue: signal(mockElementRef) },
|
|
53
|
+
],
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
afterEach(() => {
|
|
58
|
+
vi.restoreAllMocks()
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('should return a DevtoolsPanelRef', () => {
|
|
62
|
+
const result = TestBed.runInInjectionContext(() => {
|
|
63
|
+
return injectDevtoolsPanel(() => ({
|
|
64
|
+
hostElement: TestBed.inject(ElementRef),
|
|
65
|
+
}))
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
expect(result).toEqual({
|
|
69
|
+
destroy: expect.any(Function),
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('should initialize TanstackQueryDevtoolsPanel', async () => {
|
|
74
|
+
TestBed.runInInjectionContext(() => {
|
|
75
|
+
injectDevtoolsPanel(() => ({
|
|
76
|
+
hostElement: TestBed.inject(ElementRef),
|
|
77
|
+
}))
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
TestBed.tick()
|
|
81
|
+
|
|
82
|
+
await waitForDevtoolsToBeCreated()
|
|
83
|
+
|
|
84
|
+
expect(mockDevtoolsPanelInstance.mount).toHaveBeenCalledTimes(1)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('should destroy TanstackQueryDevtoolsPanel', async () => {
|
|
88
|
+
const result = TestBed.runInInjectionContext(() => {
|
|
89
|
+
return injectDevtoolsPanel(() => ({
|
|
90
|
+
hostElement: TestBed.inject(ElementRef),
|
|
91
|
+
}))
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
TestBed.tick()
|
|
95
|
+
|
|
96
|
+
await waitForDevtoolsToBeCreated()
|
|
97
|
+
|
|
98
|
+
result.destroy()
|
|
99
|
+
|
|
100
|
+
expect(mockDevtoolsPanelInstance.unmount).toHaveBeenCalledTimes(1)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('should destroy TanstackQueryDevtoolsPanel when hostElement is removed', async () => {
|
|
104
|
+
const hostElement = signal<ElementRef>(mockElementRef)
|
|
105
|
+
|
|
106
|
+
TestBed.runInInjectionContext(() => {
|
|
107
|
+
return injectDevtoolsPanel(() => ({
|
|
108
|
+
hostElement: hostElement(),
|
|
109
|
+
}))
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
TestBed.tick()
|
|
113
|
+
|
|
114
|
+
await waitForDevtoolsToBeCreated()
|
|
115
|
+
|
|
116
|
+
expect(mockDevtoolsPanelInstance.unmount).toHaveBeenCalledTimes(0)
|
|
117
|
+
|
|
118
|
+
hostElement.set(null as unknown as ElementRef)
|
|
119
|
+
|
|
120
|
+
TestBed.tick()
|
|
121
|
+
|
|
122
|
+
expect(mockDevtoolsPanelInstance.unmount).toHaveBeenCalledTimes(1)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it('should update client', async () => {
|
|
126
|
+
const client = signal(new QueryClient())
|
|
127
|
+
|
|
128
|
+
TestBed.runInInjectionContext(() => {
|
|
129
|
+
return injectDevtoolsPanel(() => ({
|
|
130
|
+
hostElement: TestBed.inject(ElementRef),
|
|
131
|
+
client: client(),
|
|
132
|
+
}))
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
TestBed.tick()
|
|
136
|
+
|
|
137
|
+
await waitForDevtoolsToBeCreated()
|
|
138
|
+
|
|
139
|
+
expect(mockDevtoolsPanelInstance.setClient).toHaveBeenCalledTimes(0)
|
|
140
|
+
|
|
141
|
+
client.set(new QueryClient())
|
|
142
|
+
|
|
143
|
+
TestBed.tick()
|
|
144
|
+
|
|
145
|
+
expect(mockDevtoolsPanelInstance.setClient).toHaveBeenCalledTimes(1)
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
it('should update error types', async () => {
|
|
149
|
+
const errorTypes = signal([])
|
|
150
|
+
|
|
151
|
+
TestBed.runInInjectionContext(() => {
|
|
152
|
+
return injectDevtoolsPanel(() => ({
|
|
153
|
+
hostElement: TestBed.inject(ElementRef),
|
|
154
|
+
errorTypes: errorTypes(),
|
|
155
|
+
}))
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
TestBed.tick()
|
|
159
|
+
|
|
160
|
+
await waitForDevtoolsToBeCreated()
|
|
161
|
+
|
|
162
|
+
expect(mockDevtoolsPanelInstance.setErrorTypes).toHaveBeenCalledTimes(0)
|
|
163
|
+
|
|
164
|
+
errorTypes.set([])
|
|
165
|
+
|
|
166
|
+
TestBed.tick()
|
|
167
|
+
|
|
168
|
+
expect(mockDevtoolsPanelInstance.setErrorTypes).toHaveBeenCalledTimes(1)
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
it('should update onclose', async () => {
|
|
172
|
+
const functionA = () => {}
|
|
173
|
+
const functionB = () => {}
|
|
174
|
+
|
|
175
|
+
const onClose = signal(functionA)
|
|
176
|
+
|
|
177
|
+
TestBed.runInInjectionContext(() => {
|
|
178
|
+
return injectDevtoolsPanel(() => ({
|
|
179
|
+
hostElement: TestBed.inject(ElementRef),
|
|
180
|
+
onClose: onClose(),
|
|
181
|
+
}))
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
TestBed.tick()
|
|
185
|
+
|
|
186
|
+
await waitForDevtoolsToBeCreated()
|
|
187
|
+
|
|
188
|
+
expect(mockDevtoolsPanelInstance.setOnClose).toHaveBeenCalledTimes(0)
|
|
189
|
+
|
|
190
|
+
onClose.set(functionB)
|
|
191
|
+
|
|
192
|
+
TestBed.tick()
|
|
193
|
+
|
|
194
|
+
expect(mockDevtoolsPanelInstance.setOnClose).toHaveBeenCalledTimes(1)
|
|
195
|
+
})
|
|
196
|
+
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { TestBed } from '@angular/core/testing'
|
|
2
|
+
import { afterEach, beforeEach, describe, expectTypeOf, it, vi } from 'vitest'
|
|
3
|
+
import { provideZonelessChangeDetection } from '@angular/core'
|
|
4
|
+
import { queryKey, sleep } from '@tanstack/query-test-utils'
|
|
5
|
+
import {
|
|
6
|
+
QueryClient,
|
|
7
|
+
injectInfiniteQuery,
|
|
8
|
+
provideTanStackQuery,
|
|
9
|
+
skipToken,
|
|
10
|
+
} from '..'
|
|
11
|
+
import type { InfiniteData } from '@tanstack/query-core'
|
|
12
|
+
|
|
13
|
+
describe('injectInfiniteQuery', () => {
|
|
14
|
+
let queryClient: QueryClient
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
queryClient = new QueryClient()
|
|
18
|
+
vi.useFakeTimers()
|
|
19
|
+
TestBed.configureTestingModule({
|
|
20
|
+
providers: [
|
|
21
|
+
provideZonelessChangeDetection(),
|
|
22
|
+
provideTanStackQuery(queryClient),
|
|
23
|
+
],
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
vi.useRealTimers()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('should narrow type after isSuccess', () => {
|
|
32
|
+
const key = queryKey()
|
|
33
|
+
const query = TestBed.runInInjectionContext(() => {
|
|
34
|
+
return injectInfiniteQuery(() => ({
|
|
35
|
+
queryKey: key,
|
|
36
|
+
queryFn: ({ pageParam }) =>
|
|
37
|
+
sleep(0).then(() => 'data on page ' + pageParam),
|
|
38
|
+
initialPageParam: 0,
|
|
39
|
+
getNextPageParam: () => 12,
|
|
40
|
+
}))
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
if (query.isSuccess()) {
|
|
44
|
+
const data = query.data()
|
|
45
|
+
expectTypeOf(data).toEqualTypeOf<InfiniteData<string, unknown>>()
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('should work when queryFn is skipToken', () => {
|
|
50
|
+
const key = queryKey()
|
|
51
|
+
const query = TestBed.runInInjectionContext(() => {
|
|
52
|
+
return injectInfiniteQuery(() => ({
|
|
53
|
+
queryKey: key,
|
|
54
|
+
queryFn: skipToken,
|
|
55
|
+
initialPageParam: 0,
|
|
56
|
+
getNextPageParam: () => 1,
|
|
57
|
+
}))
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
// TPageParam falls back to `unknown` here (unlike `infiniteQueryOptions`, which infers
|
|
61
|
+
// `number` for the same options) because there's no skipToken-specific overload to carry it.
|
|
62
|
+
expectTypeOf(query.data()).toEqualTypeOf<
|
|
63
|
+
InfiniteData<unknown, unknown> | undefined
|
|
64
|
+
>()
|
|
65
|
+
})
|
|
66
|
+
})
|