-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(solid-query): export queryOptions without type errors
#9668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(solid-query): export queryOptions without type errors
#9668
Conversation
| queryFn: () => Promise.resolve(1), | ||
| }) | ||
|
|
||
| expectTypeOf(queryKey[dataTagErrorSymbol]).toEqualTypeOf<Error>() |
There was a problem hiding this comment.
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"
|
View your CI Pipeline Execution ↗ for commit 79cf946
☁️ Nx Cloud last updated this comment at |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
🚀 New features to boost your workflow:
|
WalkthroughType-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
Sequence Diagram(s)Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
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.
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. Comment |
There was a problem hiding this 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 queryKeyThis 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
📒 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 confirmedBoth 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 exportedConfirmed: packages/query-core/src/types.ts exports dataTagErrorSymbol and packages/query-core/src/index.ts re-exports './types'.
| queryKey: DataTag<TQueryKey, TQueryFnData, TError> | ||
| } |
There was a problem hiding this comment.
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"
doneLength 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.
…#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>
fixes #8833
error repro: 1, 2
added a test case but to replicate the export behaviour we can also create a
solid-vite-tsproject underquery/integrationsand see that the export error is gone after building and exporting queryOptions from this pr (withdeclarationsset to true in the tsconfig)Summary by CodeRabbit