Skip to content

fix query option declaration emit#10583

Open
artemxknpv wants to merge 1 commit intoTanStack:mainfrom
artemxknpv:codex/fix-query-options-declaration-emit
Open

fix query option declaration emit#10583
artemxknpv wants to merge 1 commit intoTanStack:mainfrom
artemxknpv:codex/fix-query-options-declaration-emit

Conversation

@artemxknpv
Copy link
Copy Markdown

@artemxknpv artemxknpv commented Apr 25, 2026

fixes #8453

This fixes TS4023 errors when a consumer exports an inferred queryOptions or infiniteQueryOptions value while emitting declarations.

The issue is that these helpers returned anonymous intersections like:

Options & { queryKey: DataTag<...> }

When TypeScript tried to emit a consumer .d.ts, it had to expand the tagged queryKey type and could end up referencing the internal dataTagSymbol / dataTagErrorSymbol unique symbols directly.

This patch keeps the same runtime behavior and the same tagged queryKey inference, but gives those return types exported names instead. That lets declaration emit reference the helper result type instead of expanding the internal tag fields.

The patch covers the adapters that had the same tagged return shape. Svelte only changes queryOptions, because its infiniteQueryOptions does not add a tagged queryKey return type.

I kept the committed regression tests small: they force declaration emit to name exported option values. I also verified the overload branches separately with a temporary consumer project that imports from package roots.

Verification:

  • consumer-style declaration emit repro using package root imports for all touched adapters
  • TypeScript 5.4, 5.5, 5.6, 5.7, 5.8, 5.9, 6.0 RC, and current
  • test:types:ts54 through test:types:ts60 for react, preact, vue, solid, angular experimental
  • test:types for svelte
  • test:eslint
  • prettier --check
  • git diff --check

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Fixed TypeScript declaration file generation for queryOptions and infiniteQueryOptions across all query packages. Exported query option types now properly emit without exposing internal implementation details, improving type clarity for TypeScript consumers. Refactored return types to use stable, named result types that maintain consistent type names across package boundaries.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f77c9e11-178b-4d73-9406-ec75c40c5638

📥 Commits

Reviewing files that changed from the base of the PR and between c5ab5a1 and 80fe4d5.

📒 Files selected for processing (29)
  • .changeset/fix-query-options-declaration-emit.md
  • packages/angular-query-experimental/src/__tests__/infinite-query-options.test-d.ts
  • packages/angular-query-experimental/src/__tests__/query-options.test-d.ts
  • packages/angular-query-experimental/src/index.ts
  • packages/angular-query-experimental/src/infinite-query-options.ts
  • packages/angular-query-experimental/src/query-options.ts
  • packages/preact-query/src/__tests__/infiniteQueryOptions.test-d.tsx
  • packages/preact-query/src/__tests__/queryOptions.test-d.tsx
  • packages/preact-query/src/index.ts
  • packages/preact-query/src/infiniteQueryOptions.ts
  • packages/preact-query/src/queryOptions.ts
  • packages/react-query/src/__tests__/infiniteQueryOptions.test-d.tsx
  • packages/react-query/src/__tests__/queryOptions.test-d.tsx
  • packages/react-query/src/index.ts
  • packages/react-query/src/infiniteQueryOptions.ts
  • packages/react-query/src/queryOptions.ts
  • packages/solid-query/src/__tests__/infiniteQueryOptions.test-d.tsx
  • packages/solid-query/src/__tests__/queryOptions.test-d.tsx
  • packages/solid-query/src/index.ts
  • packages/solid-query/src/infiniteQueryOptions.ts
  • packages/solid-query/src/queryOptions.ts
  • packages/svelte-query/src/index.ts
  • packages/svelte-query/src/queryOptions.ts
  • packages/svelte-query/tests/queryOptions.test-d.ts
  • packages/vue-query/src/__tests__/infiniteQueryOptions.test-d.ts
  • packages/vue-query/src/__tests__/queryOptions.test-d.ts
  • packages/vue-query/src/index.ts
  • packages/vue-query/src/infiniteQueryOptions.ts
  • packages/vue-query/src/queryOptions.ts

📝 Walkthrough

Walkthrough

This pull request fixes a TypeScript declaration emit issue where exported results from queryOptions() and infiniteQueryOptions() factories caused compilation errors due to internal dataTagSymbol and dataTagErrorSymbol references leaking into .d.ts files. The fix extracts inline return type intersections into named type aliases across all TanStack query packages and adds declaration emit test coverage.

Changes

Cohort / File(s) Summary
Changeset Documentation
.changeset/fix-query-options-declaration-emit.md
Documents the fix that enables proper TypeScript declaration emit for exported queryOptions and infiniteQueryOptions results by preventing internal data tag symbols from leaking into .d.ts files.
Query Options Test Coverage
packages/angular-query-experimental/src/__tests__/query-options.test-d.ts, packages/preact-query/src/__tests__/queryOptions.test-d.tsx, packages/react-query/src/__tests__/queryOptions.test-d.tsx, packages/solid-query/src/__tests__/queryOptions.test-d.tsx, packages/svelte-query/tests/queryOptions.test-d.ts, packages/vue-query/src/__tests__/queryOptions.test-d.ts
Added exported queryOptions result constants to test declaration emit behavior and ensure inferred types remain nameable without internal symbol expansion.
Infinite Query Options Test Coverage
packages/angular-query-experimental/src/__tests__/infinite-query-options.test-d.ts, packages/preact-query/src/__tests__/infiniteQueryOptions.test-d.tsx, packages/react-query/src/__tests__/infiniteQueryOptions.test-d.tsx, packages/solid-query/src/__tests__/infiniteQueryOptions.test-d.tsx, packages/vue-query/src/__tests__/infiniteQueryOptions.test-d.ts
Added exported infiniteQueryOptions result constants to validate declaration emit for infinite query options across packages.
Query Options Type Refactoring
packages/angular-query-experimental/src/queryOptions.ts, packages/preact-query/src/queryOptions.ts, packages/react-query/src/queryOptions.ts, packages/solid-query/src/queryOptions.ts, packages/svelte-query/src/queryOptions.ts, packages/vue-query/src/queryOptions.ts
Extracted inline return type intersections into named result type aliases (DefinedInitialDataOptionsResult, UndefinedInitialDataOptionsResult, UnusedSkipTokenOptionsResult). Updated all queryOptions overloads to return these new named types.
Infinite Query Options Type Refactoring
packages/angular-query-experimental/src/infiniteQueryOptions.ts, packages/preact-query/src/infiniteQueryOptions.ts, packages/react-query/src/infiniteQueryOptions.ts, packages/solid-query/src/infiniteQueryOptions.ts, packages/vue-query/src/infiniteQueryOptions.ts
Extracted inline return type intersections into named result type aliases (DefinedInitialDataInfiniteOptionsResult, UndefinedInitialDataInfiniteOptionsResult, UnusedSkipTokenInfiniteOptionsResult). Updated all infiniteQueryOptions overloads to return these new named types.
Public API Re-exports
packages/angular-query-experimental/src/index.ts, packages/preact-query/src/index.ts, packages/react-query/src/index.ts, packages/solid-query/src/index.ts, packages/svelte-query/src/index.ts, packages/vue-query/src/index.ts
Extended public type surface by re-exporting new result type aliases from queryOptions and infiniteQueryOptions modules, making them available to library consumers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Exported types now dance with glee,
No hidden symbols shall they see!
Named result types, shiny and bright,
Make declaration emit just right!
Query options leap, infinite soar,
TypeScript errors are here no more!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix query option declaration emit' directly addresses the main change—fixing TS4023 errors in declaration emit for queryOptions and infiniteQueryOptions by naming return types.
Description check ✅ Passed The PR description comprehensively explains the issue (TS4023 errors from anonymous intersections), the solution (exported named result types), scope (covered adapters), and verification (multiple TypeScript versions and test suites).
Linked Issues check ✅ Passed The PR fully addresses #8453 by converting anonymous intersection return types to exported named result types, preventing TypeScript from expanding internal dataTagSymbol references during declaration emit.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue: fixing declaration emit for queryOptions and infiniteQueryOptions by introducing named result types and regression tests across affected adapters.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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

@artemxknpv artemxknpv force-pushed the codex/fix-query-options-declaration-emit branch from 3146fbe to 80fe4d5 Compare April 29, 2026 08:51
@artemxknpv artemxknpv marked this pull request as ready for review April 29, 2026 09:27
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.

TypeScript errors when using exported queryOptions factory in @tanstack/react-query 5.62.8

1 participant