Skip to content

fix(db-sqlite-persistence-core): add schema-aware overloads to persistedCollectionOptions#1453

Open
merodiro wants to merge 1 commit intoTanStack:mainfrom
merodiro:fix/persisted-collection-schema-types
Open

fix(db-sqlite-persistence-core): add schema-aware overloads to persistedCollectionOptions#1453
merodiro wants to merge 1 commit intoTanStack:mainfrom
merodiro:fix/persisted-collection-schema-types

Conversation

@merodiro
Copy link
Copy Markdown

@merodiro merodiro commented Apr 4, 2026

Closes #1452

Summary

  • persistedCollectionOptions was missing schema-aware overloads, so TSchema defaulted to never when a schema was passed, making the result incompatible with createCollection
  • Added four schema/no-schema overloads matching the pattern used by localOnlyCollectionOptions and localStorageCollectionOptions
  • Added type tests covering schema inference and createCollection compatibility for both sync-present and sync-absent modes

Note on error messages

Adding schema-aware overloads changes the order TypeScript evaluates overloads when a call is invalid. Previously, calling persistedCollectionOptions without persistence in sync-present mode would report the error on the function call itself. Now TypeScript reports it on the sync property inside the object literal, since the last overload it tries is the sync-absent one (which Omits sync). The type safety is unchanged - the call still fails to compile without persistence - only the error location and message differ. This is the same behavior seen in createCollection, which has 8 overloads.

Test plan

  • npx tsc --noEmit passes with zero errors
  • npx vitest run --typecheck passes (8 type tests in persisted.test-d.ts)
  • Existing tests unchanged and passing
  • Verified no breakage in other packages using persistedCollectionOptions with 2 or 4 explicit type args

…tedCollectionOptions

persistedCollectionOptions was missing schema-aware overloads, causing
TSchema to default to `never` when a schema was passed. This made the
result incompatible with createCollection's schema overloads.

Add four overloads matching the pattern used by localOnlyCollectionOptions
and localStorageCollectionOptions:
- schema provided + sync present
- schema provided + sync absent
- no schema + sync present
- no schema + sync absent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

persistedCollectionOptions: schema type parameter not inferred, result incompatible with createCollection

1 participant