Skip to content

Commit 3f56a86

Browse files
authored
test(svelte-query): add 'assertType' and 'expectTypeOf' to type tests with no assertions (#10450)
* test(svelte-query): add 'assertType' to type tests with no assertions * test(svelte-query): replace 'assertType' with 'expectTypeOf' for 'initialData' type validation
1 parent 3d95119 commit 3f56a86

2 files changed

Lines changed: 27 additions & 18 deletions

File tree

packages/svelte-query/tests/infiniteQueryOptions.test-d.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expectTypeOf, test } from 'vitest'
1+
import { assertType, describe, expectTypeOf, test } from 'vitest'
22
import { QueryClient } from '@tanstack/query-core'
33
import { queryKey } from '@tanstack/query-test-utils'
44
import { createInfiniteQuery, infiniteQueryOptions } from '../src/index.js'
@@ -7,14 +7,16 @@ import type { InfiniteData } from '@tanstack/query-core'
77
describe('infiniteQueryOptions', () => {
88
test('Should not allow excess properties', () => {
99
const key = queryKey()
10-
infiniteQueryOptions({
11-
queryKey: key,
12-
queryFn: () => Promise.resolve('data'),
13-
getNextPageParam: () => 1,
14-
initialPageParam: 1,
15-
// @ts-expect-error this is a good error, because stallTime does not exist!
16-
stallTime: 1000,
17-
})
10+
assertType(
11+
infiniteQueryOptions({
12+
queryKey: key,
13+
queryFn: () => Promise.resolve('data'),
14+
getNextPageParam: () => 1,
15+
initialPageParam: 1,
16+
// @ts-expect-error this is a good error, because stallTime does not exist!
17+
stallTime: 1000,
18+
}),
19+
)
1820
})
1921

2022
test('Should infer types for callbacks', () => {

packages/svelte-query/tests/queryOptions.test-d.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expectTypeOf, test } from 'vitest'
1+
import { assertType, describe, expectTypeOf, test } from 'vitest'
22
import {
33
QueriesObserver,
44
QueryClient,
@@ -12,12 +12,14 @@ import type { QueryObserverResult } from '@tanstack/query-core'
1212
describe('queryOptions', () => {
1313
test('Should not allow excess properties', () => {
1414
const key = queryKey()
15-
queryOptions({
16-
queryKey: key,
17-
queryFn: () => Promise.resolve(5),
18-
// @ts-expect-error this is a good error, because stallTime does not exist!
19-
stallTime: 1000,
20-
})
15+
assertType(
16+
queryOptions({
17+
queryKey: key,
18+
queryFn: () => Promise.resolve(5),
19+
// @ts-expect-error this is a good error, because stallTime does not exist!
20+
stallTime: 1000,
21+
}),
22+
)
2123
})
2224

2325
test('Should infer types for callbacks', () => {
@@ -193,9 +195,10 @@ describe('queryOptions', () => {
193195
})
194196

195197
test('Should allow undefined response in initialData', () => {
196-
return (id: string | null) =>
198+
const key = queryKey()
199+
const options = (id: string | null) =>
197200
queryOptions({
198-
queryKey: ['todo', id],
201+
queryKey: [...key, id],
199202
queryFn: () =>
200203
Promise.resolve({
201204
id: '1',
@@ -209,5 +212,9 @@ describe('queryOptions', () => {
209212
title: 'Initial Data',
210213
},
211214
})
215+
216+
expectTypeOf(options(null).initialData).returns.toEqualTypeOf<
217+
{ id: string; title: string } | undefined
218+
>()
212219
})
213220
})

0 commit comments

Comments
 (0)