Describe the bug
When passing a schema to persistedCollectionOptions, TypeScript fails to infer the TSchema type parameter. This causes two problems:
- Schema type not inferred:
options.schema resolves to undefined instead of the actual schema type (e.g. a Zod schema). TSchema defaults to never.
- Incompatible with
createCollection: The result cannot be passed to createCollection because:
createCollection's schema overloads require { schema: T } (required)
createCollection's no-schema overloads require { schema?: never }
- The result has
schema?: TSchema | undefined (optional), which matches neither
Root cause
persistedCollectionOptions lacks schema-aware overloads. Compare with localOnlyCollectionOptions (which works correctly) — it has separate overloads for the schema and no-schema cases with & { schema: T } / & { schema?: never } on both input and output types.
persistedCollectionOptions only has two overloads (sync-present vs sync-absent), neither of which distinguishes the schema case.
To Reproduce
import { z } from 'zod'
import { createCollection } from '@tanstack/db'
import { persistedCollectionOptions } from '@tanstack/db-sqlite-persistence-core'
const todoSchema = z.object({
id: z.string(),
title: z.string(),
})
const adapter = {
loadSubset: () => Promise.resolve([]),
applyCommittedTx: () => Promise.resolve(),
ensureIndex: () => Promise.resolve(),
}
// TSchema defaults to `never` — schema type is lost
const options = persistedCollectionOptions({
id: 'test',
schema: todoSchema,
schemaVersion: 1,
getKey: (item) => item.id,
persistence: { adapter },
})
// options.schema is `undefined` instead of `typeof todoSchema`
// This errors: "No overload matches this call"
const collection = createCollection(options)
Expected behavior
persistedCollectionOptions should infer the schema type and produce a result compatible with createCollection, matching the behavior of localOnlyCollectionOptions.
Additional context
The fix requires adding schema-aware overloads to persistedCollectionOptions (for both sync-present and sync-absent modes), following the same pattern used by localOnlyCollectionOptions in packages/db/src/local-only.ts.
Describe the bug
When passing a
schematopersistedCollectionOptions, TypeScript fails to infer theTSchematype parameter. This causes two problems:options.schemaresolves toundefinedinstead of the actual schema type (e.g. a Zod schema).TSchemadefaults tonever.createCollection: The result cannot be passed tocreateCollectionbecause:createCollection's schema overloads require{ schema: T }(required)createCollection's no-schema overloads require{ schema?: never }schema?: TSchema | undefined(optional), which matches neitherRoot cause
persistedCollectionOptionslacks schema-aware overloads. Compare withlocalOnlyCollectionOptions(which works correctly) — it has separate overloads for the schema and no-schema cases with& { schema: T }/& { schema?: never }on both input and output types.persistedCollectionOptionsonly has two overloads (sync-present vs sync-absent), neither of which distinguishes the schema case.To Reproduce
Expected behavior
persistedCollectionOptionsshould infer the schema type and produce a result compatible withcreateCollection, matching the behavior oflocalOnlyCollectionOptions.Additional context
The fix requires adding schema-aware overloads to
persistedCollectionOptions(for both sync-present and sync-absent modes), following the same pattern used bylocalOnlyCollectionOptionsinpackages/db/src/local-only.ts.