Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

useLiveInfiniteQuery.test-d.ts

38 lines1.2 KB

1import { describe, expectTypeOf, it } from 'vitest'
2import { useLiveInfiniteQuery } from '../src/useLiveInfiniteQuery.svelte.js'
3import type {
4 UseLiveInfiniteQueryConfig,
5 UseLiveInfiniteQueryReturn,
6} from '../src/useLiveInfiniteQuery.svelte.js'
7import type { Context, InitialQueryBuilder } from '@tanstack/db'
8​
9describe(`useLiveInfiniteQuery type assertions`, () => {
10 it(`does not advertise a server-page callback`, () => {
11 expectTypeOf<
12 Extract<keyof UseLiveInfiniteQueryConfig<Context>, `getNextPageParam`>
13 >().toEqualTypeOf<never>()
14 })
15​
16 it(`keeps legacy generic wrappers source-compatible`, () => {
17 function acceptsContext<TContext extends Context>(
18 _config: UseLiveInfiniteQueryConfig<TContext>,
19 _result: UseLiveInfiniteQueryReturn<TContext>,
20 ): void {}
21​
22 void acceptsContext
23 })
24​
25 it(`preserves the awaitable fetch callback`, () => {
26 expectTypeOf<
27 UseLiveInfiniteQueryReturn<Context>[`fetchNextPage`]
28 >().toEqualTypeOf<() => Promise<void>>()
29 })
30​
31 it(`does not advertise disabled null queries`, () => {
32 useLiveInfiniteQuery(
33 // @ts-expect-error Infinite queries do not support disabled null queries.
34 (_q: InitialQueryBuilder) => null,
35 { pageSize: 5 },
36 )
37 })
38})