Describe the bug
After upgrading from @tanstack/db@0.5.33 to @tanstack/db@0.6.0, useLiveQuery on a collection created with createLiveQueryCollection resolves data as {}[] instead of the expected row type. All property access on rows becomes a type error.
Additionally, persistedCollectionOptions from @tanstack/browser-db-sqlite-persistence erases the generic T when queryCollectionOptions() output is spread into it — T becomes object.
To Reproduce
- Create a collection with
createCollection(queryCollectionOptions({schema: portfoliosSchema, ...}))
- Create a live query collection:
createLiveQueryCollection((q) => q.from({p: portfoliosCollection}).where(...))
- Use it in a component:
const { data: [portfolio] } = useLiveQuery(portfolioByIdQuery)
- Access
portfolio.id → TS2339: Property 'id' does not exist on type '{}'
Expected behavior
portfolio should be typed as the row type inferred from the collection's schema (e.g. Portfolio), preserving all field types from the Zod schema.
Minimal repro
import { createCollection, createLiveQueryCollection, eq } from '@tanstack/db'
import { queryCollectionOptions } from '@tanstack/query-db-collection'
import { useLiveQuery } from '@tanstack/react-db'
import { z } from 'zod'
const schema = z.object({ id: z.string(), name: z.string() })
type Item = z.infer<typeof schema>
const itemsCollection = createCollection(
queryCollectionOptions({
id: 'items',
schema,
getKey: (item) => item.id,
queryKey: ['items'],
queryFn: async () => [] as Item[],
queryClient,
}),
)
const itemByIdQuery = createLiveQueryCollection((q) =>
q.from({ i: itemsCollection }).where(({ i }) => eq(i.id, 'some-id')),
)
// In component:
const { data: [item] } = useLiveQuery(itemByIdQuery)
item.id // TS2339: Property 'id' does not exist on type '{}'
item.name // TS2339: Property 'name' does not exist on type '{}'
Works on: @tanstack/react-db@0.1.77 + @tanstack/db@0.5.33
Broken on: @tanstack/react-db@0.1.78 + @tanstack/db@0.6.0
Desktop:
- OS: macOS 15.3 (arm64)
- TypeScript: 5.9.3
- Bun: 1.3.10
@tanstack/react-db: 0.1.78
@tanstack/db: 0.6.0
@tanstack/query-db-collection: 1.0.31
Additional context
Secondary issue: persistedCollectionOptions also erases generics when wrapping queryCollectionOptions via spread:
persistedCollectionOptions({
persistence,
schemaVersion: 1,
...queryCollectionOptions({ schema, getKey: (item) => item.id, ... })
// getKey callback: TS2339: Property 'id' does not exist on type 'object'
})
TypeScript cannot infer T through the spread of another generic function's return.
Workaround: Pin to pre-0.6: @tanstack/react-db@0.1.77 + @tanstack/query-db-collection@1.0.30.
Describe the bug
After upgrading from
@tanstack/db@0.5.33to@tanstack/db@0.6.0,useLiveQueryon a collection created withcreateLiveQueryCollectionresolvesdataas{}[]instead of the expected row type. All property access on rows becomes a type error.Additionally,
persistedCollectionOptionsfrom@tanstack/browser-db-sqlite-persistenceerases the genericTwhenqueryCollectionOptions()output is spread into it —Tbecomesobject.To Reproduce
createCollection(queryCollectionOptions({schema: portfoliosSchema, ...}))createLiveQueryCollection((q) => q.from({p: portfoliosCollection}).where(...))const { data: [portfolio] } = useLiveQuery(portfolioByIdQuery)portfolio.id→TS2339: Property 'id' does not exist on type '{}'Expected behavior
portfolioshould be typed as the row type inferred from the collection's schema (e.g.Portfolio), preserving all field types from the Zod schema.Minimal repro
Works on:
@tanstack/react-db@0.1.77+@tanstack/db@0.5.33Broken on:
@tanstack/react-db@0.1.78+@tanstack/db@0.6.0Desktop:
@tanstack/react-db: 0.1.78@tanstack/db: 0.6.0@tanstack/query-db-collection: 1.0.31Additional context
Secondary issue:
persistedCollectionOptionsalso erases generics when wrappingqueryCollectionOptionsvia spread:TypeScript cannot infer
Tthrough the spread of another generic function's return.Workaround: Pin to pre-0.6:
@tanstack/react-db@0.1.77+@tanstack/query-db-collection@1.0.30.