Skip to content

Conversation

@Zen-cronic
Copy link
Contributor

@Zen-cronic Zen-cronic commented Sep 20, 2025

fixes #8833

  • error repro: 1, 2

  • added a test case but to replicate the export behaviour we can also create a solid-vite-ts project under query/integrations and see that the export error is gone after building and exporting queryOptions from this pr (with declarations set to true in the tsconfig)

Summary by CodeRabbit

  • New Features
    • Enhanced type safety: queryOptions now encodes the error type in queryKey, improving inference and consistency with default query functions.
  • Refactor
    • Simplified generics in queryOptions type declarations with no runtime impact.
  • Tests
    • Added a type-level test ensuring queryKey defaults to an Error-typed tag when a default query function returns a value.

queryFn: () => Promise.resolve(1),
})

expectTypeOf(queryKey[dataTagErrorSymbol]).toEqualTypeOf<Error>()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

before the fix, this was typeof unsetMarker which ts treated as an "inaccessible unique symbol"

@nx-cloud
Copy link

nx-cloud bot commented Sep 21, 2025

View your CI Pipeline Execution ↗ for commit 79cf946

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m 37s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 10s View ↗

☁️ Nx Cloud last updated this comment at 2025-09-24 11:29:07 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Sep 21, 2025

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@9668

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@9668

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@9668

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@9668

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@9668

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@9668

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@9668

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@9668

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@9668

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@9668

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@9668

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@9668

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@9668

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@9668

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@9668

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@9668

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@9668

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@9668

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@9668

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@9668

commit: 79cf946

@codecov
Copy link

codecov bot commented Sep 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.39%. Comparing base (2cf3ec9) to head (79cf946).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #9668       +/-   ##
===========================================
+ Coverage   46.38%   79.39%   +33.01%     
===========================================
  Files         214       15      -199     
  Lines        8488      330     -8158     
  Branches     1928       62     -1866     
===========================================
- Hits         3937      262     -3675     
+ Misses       4108       56     -4052     
+ Partials      443       12      -431     
Components Coverage Δ
@tanstack/angular-query-experimental ∅ <ø> (∅)
@tanstack/eslint-plugin-query ∅ <ø> (∅)
@tanstack/query-async-storage-persister ∅ <ø> (∅)
@tanstack/query-broadcast-client-experimental ∅ <ø> (∅)
@tanstack/query-codemods ∅ <ø> (∅)
@tanstack/query-core ∅ <ø> (∅)
@tanstack/query-devtools ∅ <ø> (∅)
@tanstack/query-persist-client-core ∅ <ø> (∅)
@tanstack/query-sync-storage-persister ∅ <ø> (∅)
@tanstack/query-test-utils ∅ <ø> (∅)
@tanstack/react-query ∅ <ø> (∅)
@tanstack/react-query-devtools ∅ <ø> (∅)
@tanstack/react-query-next-experimental ∅ <ø> (∅)
@tanstack/react-query-persist-client ∅ <ø> (∅)
@tanstack/solid-query 78.06% <ø> (ø)
@tanstack/solid-query-devtools ∅ <ø> (∅)
@tanstack/solid-query-persist-client 100.00% <ø> (ø)
@tanstack/svelte-query ∅ <ø> (∅)
@tanstack/svelte-query-devtools ∅ <ø> (∅)
@tanstack/svelte-query-persist-client ∅ <ø> (∅)
@tanstack/vue-query ∅ <ø> (∅)
@tanstack/vue-query-devtools ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 24, 2025

Walkthrough

Type-level updates to queryOptions: removed a generic parameter and expanded DataTag to include TError. A dts test imports dataTagErrorSymbol and adds a test asserting a default error type tag on queryKey. No runtime logic changes.

Changes

Cohort / File(s) Summary
Query options type API
packages/solid-query/src/queryOptions.ts
Removed generic parameter TOptions from both overloads of queryOptions. Updated return type: queryKey’s DataTag now includes TError (DataTag<TQueryKey, TQueryFnData, TError>). Implementation body unchanged.
Type tests update
packages/solid-query/src/__tests__/queryOptions.test-d.tsx
Imported dataTagErrorSymbol from @tanstack/query-core. Added test ensuring queryKey carries a default error type tag (Error) when a default queryFn returning a value is used.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

package: query-core

Suggested reviewers

  • manudeli

Poem

I thump my paws at types that err,
A tag of Error, now declared fair.
TOptions hops away—less weight to bear,
DataTag grows ears for TError’s lair.
In fields of generics, I nibble with glee,
Stronger typings for every query. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning The changes touch packages/solid-query/queryOptions.ts and add an export and test that target the TypeScript export/type error described in [#8833], so they address the core type/export issue for queryOptions. However the provided summary shows no corresponding changes to infiniteQueryOptions or tests covering the infinite-query variant, and the linked issue explicitly cites both queryOptions and infiniteQueryOptions, so the PR appears to only partially resolve the reported problem. Therefore the submission does not fully meet all objectives from the linked issue. Extend the same type/export adjustments and add equivalent tests for infiniteQueryOptions so both variants in issue #8833 are covered. Validate the fix by building with TypeScript declarations enabled and by compiling the provided reproduction cases (Angular/playground) to confirm TS2527 is resolved without manual annotations. Update the PR description to state exactly which parts of #8833 are resolved and which, if any, remain outstanding.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "fix(solid-query): export queryOptions without type errors" is concise, package-scoped, and directly communicates the primary intent to fix TypeScript export/type errors for queryOptions in the solid-query package. It is a single clear sentence without noise and matches the changes summarized in the PR. The title therefore satisfies the guidelines for clarity and relevance.
Out of Scope Changes Check ✅ Passed All reported changes are localized to packages/solid-query (queryOptions and related tests) and an added export from @tanstack/query-core, and these modifications align with the stated goal of fixing export/type errors for queryOptions. The summary does not show unrelated feature additions or edits to other packages, so there are no apparent out-of-scope modifications. The changes appear focused and relevant to the linked issue.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/solid-query/src/__tests__/queryOptions.test-d.tsx (1)

82-89: Nice: asserting default error tag type on queryKey

This validates the fix by avoiding inaccessible unique symbol leakage through the return type.

Consider adding a test that proves a custom TError propagates to the tag:

@@
   it('should tag the queryKey with the default error type', () => {
@@
     expectTypeOf(queryKey[dataTagErrorSymbol]).toEqualTypeOf<Error>()
   })
+
+  it('should tag the queryKey with a custom error type when provided', () => {
+    class MyErr extends Error {}
+    const { queryKey } = queryOptions<number, MyErr>({
+      queryKey: ['key'],
+      queryFn: () => Promise.resolve(1),
+    })
+    expectTypeOf(queryKey[dataTagErrorSymbol]).toEqualTypeOf<MyErr>()
+  })
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0eaafe0 and 79cf946.

📒 Files selected for processing (2)
  • packages/solid-query/src/__tests__/queryOptions.test-d.tsx (2 hunks)
  • packages/solid-query/src/queryOptions.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-19T03:18:18.303Z
Learnt from: oscartbeaumont
PR: TanStack/query#9564
File: packages/solid-query-devtools/src/production.tsx:2-3
Timestamp: 2025-08-19T03:18:18.303Z
Learning: In the solid-query-devtools package, the codebase uses a pattern of type-only default imports combined with typeof for component type annotations (e.g., `import type SolidQueryDevtoolsComp from './devtools'` followed by `typeof SolidQueryDevtoolsComp`). This pattern is consistently used across index.tsx and production.tsx files, and the maintainers prefer consistency over changing this approach.

Applied to files:

  • packages/solid-query/src/__tests__/queryOptions.test-d.tsx
🧬 Code graph analysis (2)
packages/solid-query/src/__tests__/queryOptions.test-d.tsx (2)
packages/solid-query/src/queryOptions.ts (1)
  • queryOptions (57-59)
packages/solid-query/src/index.ts (1)
  • queryOptions (91-91)
packages/solid-query/src/queryOptions.ts (1)
packages/query-core/src/types.ts (3)
  • DataTag (73-82)
  • DefaultError (47-51)
  • QueryKey (53-61)
🔇 Additional comments (2)
packages/solid-query/src/queryOptions.ts (1)

54-55: Overload parity confirmed

Both overloads now tag queryKey with DataTag<TQueryKey, TQueryFnData, TError>. Consistent and correct.

packages/solid-query/src/__tests__/queryOptions.test-d.tsx (1)

2-7: Imports look correct — dataTagErrorSymbol is publicly exported

Confirmed: packages/query-core/src/types.ts exports dataTagErrorSymbol and packages/query-core/src/index.ts re-exports './types'.

Comment on lines +39 to 40
queryKey: DataTag<TQueryKey, TQueryFnData, TError>
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

🧩 Analysis chain

Key fix: include TError in DataTag for queryKey

Passing TError prevents UnsetMarker from leaking into the emitted d.ts and addresses TS2527. LGTM.

Optionally verify parity across integrations to avoid regressions elsewhere:


🏁 Script executed:

#!/bin/bash
# Find queryOptions wrappers that still tag queryKey without TError.
fd --type f 'queryOptions.ts' packages | while read -r f; do
  echo ">>> $f"
  rg -nP 'queryKey:\s*DataTag<\s*[^,>]+,\s*[^,>]+\s*>' "$f"
done

# Also check for infiniteQueryOptions wrappers if present.
fd --type f 'infiniteQueryOptions.ts' packages | while read -r f; do
  echo ">>> $f"
  rg -nP 'queryKey:\s*DataTag<\s*[^,>]+,\s*[^,>]+\s*>' "$f"
done

Length of output: 962


Key fix: include TError in DataTag for queryKey across packages

Add the third generic parameter (TError) to prevent UnsetMarker leaking into emitted d.ts and resolve TS2527.

Files to update:

  • packages/svelte-query/src/queryOptions.ts — change
    queryKey: DataTag<TQueryKey, TQueryFnData>
    -> queryKey: DataTag<TQueryKey, TQueryFnData, TError> (matches ~lines 38, 49)
  • packages/solid-query/src/infiniteQueryOptions.ts — change
    queryKey: DataTag<TQueryKey, InfiniteData>
    -> queryKey: DataTag<TQueryKey, InfiniteData, TError> (matches ~lines 74, 101)

Verify parity in other packages' queryOptions.ts / infiniteQueryOptions.ts after applying.

@TkDodo TkDodo merged commit 865095d into TanStack:main Sep 24, 2025
8 checks passed
Hellol77 pushed a commit to Hellol77/query that referenced this pull request Oct 14, 2025
…#9668)

* fix(solid-query): add missing generic error type

* refactor(solid-query): remove unused generic type

* test(solid-query): add case for error tag

---------

Co-authored-by: Dominik Dorfmeister <office@dorfmeister.cc>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inferred type references an inaccessible unique symbol type after updating from 5.61.5 to 5.62.0

2 participants