Skip to content
Source
Sign inSign up
TanStack/db

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

Closedmerodiro(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/1453/headopened

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
    1. samwillis(GitHub profile, opens in a new tab) approved these changes

      Perfect, thanks @merodiro 🚀

    2. More templates

      @tanstack/angular-db

      npm i https://pkg.pr.new/@tanstack/angular-db@1453

      @tanstack/browser-db-sqlite-persistence

      npm i https://pkg.pr.new/@tanstack/browser-db-sqlite-persistence@1453

      @tanstack/capacitor-db-sqlite-persistence

      npm i https://pkg.pr.new/@tanstack/capacitor-db-sqlite-persistence@1453

      @tanstack/cloudflare-durable-objects-db-sqlite-persistence

      npm i https://pkg.pr.new/@tanstack/cloudflare-durable-objects-db-sqlite-persistence@1453

      @tanstack/db

      npm i https://pkg.pr.new/@tanstack/db@1453

      @tanstack/db-ivm

      npm i https://pkg.pr.new/@tanstack/db-ivm@1453

      @tanstack/db-sqlite-persistence-core

      npm i https://pkg.pr.new/@tanstack/db-sqlite-persistence-core@1453

      @tanstack/electric-db-collection

      npm i https://pkg.pr.new/@tanstack/electric-db-collection@1453

      @tanstack/electron-db-sqlite-persistence

      npm i https://pkg.pr.new/@tanstack/electron-db-sqlite-persistence@1453

      @tanstack/expo-db-sqlite-persistence

      npm i https://pkg.pr.new/@tanstack/expo-db-sqlite-persistence@1453

      @tanstack/node-db-sqlite-persistence

      npm i https://pkg.pr.new/@tanstack/node-db-sqlite-persistence@1453

      @tanstack/offline-transactions

      npm i https://pkg.pr.new/@tanstack/offline-transactions@1453

      @tanstack/powersync-db-collection

      npm i https://pkg.pr.new/@tanstack/powersync-db-collection@1453

      @tanstack/query-db-collection

      npm i https://pkg.pr.new/@tanstack/query-db-collection@1453

      @tanstack/react-db

      npm i https://pkg.pr.new/@tanstack/react-db@1453

      @tanstack/react-native-db-sqlite-persistence

      npm i https://pkg.pr.new/@tanstack/react-native-db-sqlite-persistence@1453

      @tanstack/rxdb-db-collection

      npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@1453

      @tanstack/solid-db

      npm i https://pkg.pr.new/@tanstack/solid-db@1453

      @tanstack/svelte-db

      npm i https://pkg.pr.new/@tanstack/svelte-db@1453

      @tanstack/tauri-db-sqlite-persistence

      npm i https://pkg.pr.new/@tanstack/tauri-db-sqlite-persistence@1453

      @tanstack/trailbase-db-collection

      npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@1453

      @tanstack/vue-db

      npm i https://pkg.pr.new/@tanstack/vue-db@1453

      commit: 78af495

    3. Closing as superseded by merged PR #1866, which fixes the same #1452 schema-inference and createCollection composition bug for both sync-wrapped and local-only persisted collections and adds focused type-oracle coverage.

Sign in to join this conversation.