Skip to content
Source
Sign inSign up
TanStack/query

fix(solid-query): export `queryOptions` without type errors #9668

MergedZen-cronic(GitHub profile, opens in a new tab)merged 5 commits intomain fromrefs/pull/9668/headmerged by TkDodo View on GitHub

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.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-query

    2. packages/solid-query/src/__tests__/queryOptions.test-d.tsx line 88
      @@ -74,3 +79,10 @@
      7479
      7580 expectTypeOf(queryKey[dataTagSymbol]).toEqualTypeOf<number>()
      7681 })
      82+ it('should tag the queryKey with the default error type', () => {
      83+ const { queryKey } = queryOptions({
      84+ queryKey: ['key'],
      85+ queryFn: () => Promise.resolve(1),
      86+ })
      87+
      88+ expectTypeOf(queryKey[dataTagErrorSymbol]).toEqualTypeOf<Error>()

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

    3. View your CI Pipeline Execution ↗ for commit 79cf9463a65ad4db5afbe3c92a8ee9230d88c3a9

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded1m 37sView ↗
      nx run-many --target=build --exclude=examples/*...✅ Succeeded10sView ↗

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

    4. 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

    5. Codecov Report

      :white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 79.39%. Comparing base (2cf3ec9) to head (79cf946). :warning: 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     
      ComponentsCoverage Δ
      @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-query78.06% <ø> (ø)
      @tanstack/solid-query-devtools∅ <ø> (∅)
      @tanstack/solid-query-persist-client100.00% <ø> (ø)
      @tanstack/svelte-query∅ <ø> (∅)
      @tanstack/svelte-query-devtools∅ <ø> (∅)
      @tanstack/svelte-query-persist-client∅ <ø> (∅)
      @tanstack/vue-query∅ <ø> (∅)
      @tanstack/vue-query-devtools∅ <ø> (∅)
      :rocket: New features to boost your workflow:
      • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
      • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
  • TkDodo approved these changes

  • 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 nameStatusExplanationResolution
    Linked Issues Check⚠️ WarningThe 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⚠️ WarningDocstring 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 nameStatusExplanation
    Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
    Title Check✅ PassedThe 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✅ PassedAll 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.
  • 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 0eaafe08212f1caceb67259046c53d9b1a1a4f9b and 79cf9463a65ad4db5afbe3c92a8ee9230d88c3a9.

    📒 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'.

    packages/solid-query/src/queryOptions.ts lines 39 to 40
    @@ -29,17 +29,12 @@
    2929 TError = DefaultError,
    3030 TData = TQueryFnData,
    3131 TQueryKey extends QueryKey = QueryKey,
    32- TOptions extends ReturnType<
    33- UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
    34- > = ReturnType<
    35- UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
    36- >,
    3732 >(
    3833 options: ReturnType<
    3934 UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
    4035 >,
    4136 ): ReturnType<
    4237 UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>
    4338 > & {
    44- queryKey: DataTag<TQueryKey, TQueryFnData>
    39+ queryKey: DataTag<TQueryKey, TQueryFnData, TError>
    4540 }

    🛠️ 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 merged this865095d

  • TkDodo closed this

  • Sign in to join this conversation.