Open History to see the last commit
1import { describe, expectTypeOf, it } from 'vitest'
2import { createCollection } from '@tanstack/db'
3import { trailBaseCollectionOptions } from '../src/trailbase'
4import type { TrailBaseCollectionUtils } from '../src/trailbase'
5import type { RecordApi } from 'trailbase'
6
7type TestItem = {
8 id: string
9 title: string
10}
11
12describe(`TrailBase collection type tests`, () => {
13 it(`should type collection.utils as TrailBaseCollectionUtils after createCollection`, () => {
14 const collection = createCollection(
15 trailBaseCollectionOptions<TestItem>({
16 id: `todos`,
17 recordApi: {} as RecordApi<TestItem>,
18 getKey: (item) => item.id,
19 parse: {},
20 serialize: {},
21 }),
22 )
23
24 // Verify that collection.utils is typed as TrailBaseCollectionUtils, not UtilsRecord
25 const utils: TrailBaseCollectionUtils = collection.utils
26 expectTypeOf(utils.cancel).toBeFunction()
27 expectTypeOf(collection.utils.cancel).toBeFunction()
28 })
29})