Skip to content

Comments

fix(query-db-collection): align queryOptions interop types#1287

Closed
hugiex wants to merge 4 commits intoTanStack:mainfrom
hugiex:feature/issue-1279-query-options-interop
Closed

fix(query-db-collection): align queryOptions interop types#1287
hugiex wants to merge 4 commits intoTanStack:mainfrom
hugiex:feature/issue-1279-query-options-interop

Conversation

@hugiex
Copy link
Contributor

@hugiex hugiex commented Feb 23, 2026

Summary

To fix this issue: #1279

This PR makes queryOptions(...) interop first-class in @tanstack/query-db-collection. You can now spread ...queryOptions(...) into queryCollectionOptions(...) without re-declaring queryKey, re-shaping enabled, or wrapping queryFn.

🎯 Changes

  1. Aligned query collection types with TanStack Query core contracts:
  • queryFn now accepts T | Promise<T> (not Promise-only).
  • enabled now aligns with QueryObserverOptions['enabled'] (boolean or callback).
  • staleTime, refetchInterval, retry, and retryDelay now follow QueryObserverOptions typing with the correct query data/key generics.
  • Added typed overloads for DataTag query keys returned by queryOptions(...).
  1. Kept runtime safety strict and unchanged:
  • queryFn is still required at runtime.
  • wrapped responses still require select to extract item arrays.
  1. Added coverage and docs:
  • Added interop tests (including sync queryFn return support).
  • Added docs section showing queryOptions(...) spread usage.
  • Intentionally did not add SkipToken support (query collections require an executable fetch function).

Why

The issue is a type-level mismatch between query-db-collection and TanStack Query option shapes. This removes boilerplate for existing Query users while preserving query-collection safety guarantees.

Reference: original TanStack Query types file

✅ Checklist

  • I have tested this code locally with pnpm test.

Note: there are some failed test files but I didn't changes them

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

@changeset-bot
Copy link

changeset-bot bot commented Feb 23, 2026

🦋 Changeset detected

Latest commit: 7a3becc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tanstack/query-db-collection Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 23, 2026

More templates

@tanstack/angular-db

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

@tanstack/db

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

@tanstack/db-ivm

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

@tanstack/electric-db-collection

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

@tanstack/offline-transactions

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

@tanstack/powersync-db-collection

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

@tanstack/query-db-collection

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

@tanstack/react-db

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

@tanstack/rxdb-db-collection

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

@tanstack/solid-db

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

@tanstack/svelte-db

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

@tanstack/trailbase-db-collection

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

@tanstack/vue-db

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

commit: 7a3becc

`queryFn` | `queryKey`
> & {
queryKey: TaggedQueryKey<TQueryKey, TQueryData, TError>
queryFn?: (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types should correspond to runtime expectations. The query function is required at runtime so this should be reflected by the type, even if that is incompatible with TanStack query options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense, I've made the changes

@kevin-dp
Copy link
Contributor

Hi @hugiex, thanks for your contribution. I think we can simplify it a bit as we don't need the entire interop overloads. These simplified typings seem to work fine: #1289. Would appreciate your thoughts about it.

@hugiex
Copy link
Contributor Author

hugiex commented Feb 23, 2026

Thanks for the suggestion! I'm totally good with simplifying it if this already covers what we need.

Happy to stick with the minimal approach as long as it fits the repo/team direction. I'll go ahead and close this PR 👍

@hugiex hugiex closed this Feb 23, 2026
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.

2 participants