fix query option declaration emit#10583
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (24)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (21)
📝 WalkthroughWalkthroughAdds a QueryKeyWithDataTag type to query-core, replaces inline DataTag intersections with that named type in queryOptions/infiniteQueryOptions overloads across adapters, adds exported regression-test constants, and includes a changeset documenting the patch. ChangesQuery Options Declaration Emit Fix
🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested Labels
Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
3146fbe to
80fe4d5
Compare
|
@TkDodo hi, quick check: is this worth a look? it keeps runtime behavior the same and only names the helper return types so d.ts emit doesn't leak the internal DataTag symbols. |
|
@TkDodo hi, sorry for another ping. is this still worth a review? |
|
View your CI Pipeline Execution ↗ for commit f745f11
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
I tested this and the fix is fine in general, however, it seems to be enough for TypeScript to only name the DataTag itself:
type QueryKeyWithDataTag<
TQueryKey extends QueryKey = QueryKey,
TQueryFnData = unknown,
TError = DefaultError,
> = {
queryKey: DataTag<TQueryKey, TQueryFnData, TError>
}
which we don’t need to export and we can add to all return types instead of the inline type:
-): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
- queryKey: DataTag<TQueryKey, TQueryFnData, TError>
-}
+): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> &
+ QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>would be good if we could use this approach please. Might even be enough to have this type QueryKeyWithDataTag once in the query core.
There was a problem hiding this comment.
updated in a34a95c. moved QueryKeyWithDataTag to query-core and switched the overload returns to use it.
Vue still needs local named aliases in queryOptions.ts for declaration emit, but they are not re-exported from the package entry.
9cf638a to
b79d9c8
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/solid-query/src/infiniteQueryOptions.ts`:
- Around line 61-62: The overloads of infiniteQueryOptions are using
QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>> and thus drop the
user-specified TError (it falls back to DefaultError); update both overload
signatures to propagate TError into the tagged key by changing the type to
QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError> so the tagged
QueryKey retains the correct error type (modify the two overload signatures in
infiniteQueryOptions that reference QueryKeyWithDataTag accordingly).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3f13d8e2-a392-439f-b4aa-e30ece70f3e2
📒 Files selected for processing (24)
.changeset/fix-query-options-declaration-emit.mdpackages/angular-query-experimental/src/__tests__/infinite-query-options.test-d.tspackages/angular-query-experimental/src/__tests__/query-options.test-d.tspackages/angular-query-experimental/src/infinite-query-options.tspackages/angular-query-experimental/src/query-options.tspackages/preact-query/src/__tests__/infiniteQueryOptions.test-d.tsxpackages/preact-query/src/__tests__/queryOptions.test-d.tsxpackages/preact-query/src/infiniteQueryOptions.tspackages/preact-query/src/queryOptions.tspackages/query-core/src/types.tspackages/react-query/src/__tests__/infiniteQueryOptions.test-d.tsxpackages/react-query/src/__tests__/queryOptions.test-d.tsxpackages/react-query/src/infiniteQueryOptions.tspackages/react-query/src/queryOptions.tspackages/solid-query/src/__tests__/infiniteQueryOptions.test-d.tsxpackages/solid-query/src/__tests__/queryOptions.test-d.tsxpackages/solid-query/src/infiniteQueryOptions.tspackages/solid-query/src/queryOptions.tspackages/svelte-query/src/queryOptions.tspackages/svelte-query/tests/queryOptions.test-d.tspackages/vue-query/src/__tests__/infiniteQueryOptions.test-d.tspackages/vue-query/src/__tests__/queryOptions.test-d.tspackages/vue-query/src/infiniteQueryOptions.tspackages/vue-query/src/queryOptions.ts
✅ Files skipped from review due to trivial changes (1)
- .changeset/fix-query-options-declaration-emit.md
🚧 Files skipped from review as they are similar to previous changes (11)
- packages/angular-query-experimental/src/tests/infinite-query-options.test-d.ts
- packages/react-query/src/tests/infiniteQueryOptions.test-d.tsx
- packages/vue-query/src/tests/infiniteQueryOptions.test-d.ts
- packages/solid-query/src/tests/infiniteQueryOptions.test-d.tsx
- packages/react-query/src/tests/queryOptions.test-d.tsx
- packages/svelte-query/tests/queryOptions.test-d.ts
- packages/vue-query/src/tests/queryOptions.test-d.ts
- packages/preact-query/src/tests/infiniteQueryOptions.test-d.tsx
- packages/preact-query/src/tests/queryOptions.test-d.tsx
- packages/angular-query-experimental/src/tests/query-options.test-d.ts
- packages/angular-query-experimental/src/query-options.ts
b79d9c8 to
a34a95c
Compare
fixes #8453
This fixes TS4023 errors when a consumer exports an inferred
queryOptionsorinfiniteQueryOptionsvalue while emitting declarations.The issue is that these helpers returned anonymous intersections like:
When TypeScript tried to emit a consumer
.d.ts, it had to expand the taggedqueryKeytype and could end up referencing the internaldataTagSymbol/dataTagErrorSymbolunique symbols directly.This patch keeps the same runtime behavior and the same tagged
queryKeyinference, 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 itsinfiniteQueryOptionsdoes not add a taggedqueryKeyreturn 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:
test:types:ts54throughtest:types:ts60for react, preact, vue, solid, angular experimentaltest:typesfor sveltetest:eslintprettier --checkgit diff --checkSummary by CodeRabbit
Bug Fixes
Tests