persistedCollectionOptions: schema type parameter not inferred, result incompatible with createCollection
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 68/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- typescript
- Ambito
- api
Direzione di ricerca
Inizia da persistedCollectionOptions e confronta i suoi overload con i pattern consapevoli dello schema in packages/db/src/local-only.ts. Verifica che sia nei casi con sync presente sia in quelli con sync assente venga preservato il tipo dello schema e che le opzioni restituite possano essere passate a createCollection; il lavoro è completato quando la riproduzione inferisce lo schema e supera il controllo dei tipi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
- I've validated the bug against the latest version of DB packages
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.schemaresolves toundefinedinstead of the actual schema type (e.g. a Zod schema).TSchemadefaults tonever. - Incompatible with
createCollection: The result cannot be passed tocreateCollectionbecause: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.
- Lingua principale
- TypeScript
- Stelle
- 3.9k
- Fork
- 266
- Merge medio
- 1g 4h
- PR unite (30g)
- 52
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/db
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Index suggestion for collection size is gated on autoIndex, so it only fires where it is redundant Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Issue simili
-
comp/desktop P3 type/bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
NousResearch/hermes-agent#118866 ·
-
Browser Waiting for: Product Owner
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
getsentry/sentry-javascript#24577 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
agilepathway/label-checker#640 ·
-
Plugin stuck at "loading" on DSH 0.1.6-alpha.2 — turnTail list slot registration missing options.id Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Add 2021 Cup data to website Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
chrisparsons83/flexspotff#153 ·