fix: normalize schema generic in PersistedSyncOptionsResult#1415
Open
ghardin1314 wants to merge 1 commit intoTanStack:mainfrom
Open
fix: normalize schema generic in PersistedSyncOptionsResult#1415ghardin1314 wants to merge 1 commit intoTanStack:mainfrom
ghardin1314 wants to merge 1 commit intoTanStack:mainfrom
Conversation
…eCollection compatibility
`persistedCollectionOptions()` wrapping `queryCollectionOptions()` produced a
`PersistedSyncOptionsResult` whose `TSchema` generic didn't match any
`createCollection` overload:
- With a concrete schema (e.g. ZodObject): `schema?: TSchema | undefined`
matched neither the "with schema" overload (`{ schema: T }`) nor the
"without schema" overload (`{ schema?: never }`).
- Without a schema: `TSchema` defaulted to `StandardSchemaV1<unknown, unknown>`
which also failed the `never` check in `createCollection`.
Add `NormalizeSchema<TSchema>` helper that collapses both `never` and the
default `StandardSchemaV1<unknown, unknown>` to `never`, then use it in
both the `CollectionConfig` generic parameter and an intersection that
makes `schema` required (concrete) or `schema?: never` (absent).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
persistedCollectionOptions()wrappingqueryCollectionOptions()produces aPersistedSyncOptionsResultwhoseTSchemageneric doesn't match anycreateCollectionoverload, causing a type error when composing persisted + query-synced collections.Repro — both of these fail:
Root cause:
PersistedSyncOptionsResultpassesTSchemathrough toCollectionConfigas-is. ButcreateCollectionhas two overload groups:{ schema: T }(required) +CollectionConfig<..., T, ...>whereT extends StandardSchemaV1{ schema?: never }+CollectionConfig<..., never, ...>When
TSchemais a concrete schema (ZodObject), the result hasschema?: TSchema | undefined(optional from CollectionConfig) — matching neither overload. WhenTSchemais the defaultStandardSchemaV1<unknown, unknown>, it also fails thenevercheck.Fix: Add a
NormalizeSchema<TSchema>helper that collapses bothneverand the defaultStandardSchemaV1<unknown, unknown>tonever, then use it in both theCollectionConfiggeneric parameter and a conditional intersection that makesschemarequired or absent.Test plan
persistedCollectionOptions({ ...queryCollectionOptions({ schema }), persistence })passed tocreateCollectioncompilespersistedCollectionOptions({ ...queryCollectionOptions({ /* no schema */ }), persistence })passed tocreateCollectioncompilespersistedCollectionOptions({ /* local-only, no sync */ })still compiles