Skip to content

Conversation

@ulrichstark
Copy link

@ulrichstark ulrichstark commented Jan 11, 2026

🎯 Changes

While testing my changes to the @typescript-eslint/no-unnecessary-type-assertion lint rule on this repo, I found these unnecessary type assertions that can be removed without impacting runtime behaviour or triggering TS errors.

typescript-eslint/typescript-eslint#11789

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Chores
    • Performed internal code quality improvements including removal of redundant type annotations and minor documentation corrections across core query and devtools packages. No changes to user-facing functionality or public APIs.

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot
Copy link

changeset-bot bot commented Jan 11, 2026

⚠️ No Changeset found

Latest commit: 9149a64

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 11, 2026

📝 Walkthrough

Walkthrough

Removes explicit type casts (QueryOptions, QueryState, and as any) and associated imports across query-core and query-devtools packages while maintaining functional equivalence. Includes a minor comment typo fix.

Changes

Cohort / File(s) Summary
Type Cast and Import Cleanup
packages/query-core/src/query.ts
Minor comment fix (retyer → retryer). Function invocation now occurs without explicit type cast in getDefaultState.
QueryOptions Removal
packages/query-core/src/queryObserver.ts
Removed QueryOptions type cast from fetch call. Removed as any type cast from error assignment. QueryOptions import eliminated.
QueryState Removal
packages/query-devtools/src/Devtools.tsx
Removed QueryState import from '@tanstack/query-core'. Removed two QueryState<unknown, Error> type casts in query state handling logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • arnoud-dv
  • TkDodo

Poem

🐰 Away with needless casts, we hop with glee,
Type safety flows as naturally as can be,
Comments cleaned and imports freed,
The code runs lighter at speed!

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: removing unnecessary type assertions across three files with no behavioral impact.
Description check ✅ Passed The description follows the template, explains the motivation clearly with a reference to the eslint PR, includes all checklist items completed, and correctly marks the change as dev-only.

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

✨ Finishing touches
  • 📝 Generate docstrings

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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/query-core/src/queryObserver.ts (1)

546-551: Use a null-check for #selectError (don’t rely on truthiness).
Since TError is generic, a falsy thrown value (e.g. '' / 0) would currently skip the error path.

Proposed fix
-    if (this.#selectError) {
-      error = this.#selectError
+    if (this.#selectError !== null) {
+      error = this.#selectError
       data = this.#selectResult
       errorUpdatedAt = Date.now()
       status = 'error'
     }
🧹 Nitpick comments (2)
packages/query-devtools/src/Devtools.tsx (2)

1958-1966: LGTM removing the QueryState<unknown, Error> cast in setState.
One thing to keep an eye on: fetchMeta is being used as an escape hatch for __previousQueryOptions via as any; if you want to tighten this later, a dedicated side-channel (e.g., WeakMap<Query, QueryOptions>) avoids mutating fetchMeta’s shape.


2183-2202: LGTM removing the QueryState<unknown, Error> cast in the loading-path setState.
Same note as above: fetchMeta: { … } as any is still an intentional escape hatch; consider a side-channel if you ever want to remove the remaining any.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44c3cb9 and 9149a64.

📒 Files selected for processing (3)
  • packages/query-core/src/query.ts
  • packages/query-core/src/queryObserver.ts
  • packages/query-devtools/src/Devtools.tsx
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: oscartbeaumont
Repo: TanStack/query PR: 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.
Learnt from: sukvvon
Repo: TanStack/query PR: 9892
File: packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx:331-335
Timestamp: 2025-11-22T09:06:05.219Z
Learning: In TanStack/query test files, when a queryFn contains side effects (e.g., setting flags for test verification), prefer async/await syntax for clarity; when there are no side effects, prefer the .then() pattern for conciseness.
📚 Learning: 2025-08-19T03:18:18.303Z
Learnt from: oscartbeaumont
Repo: TanStack/query PR: 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/query-core/src/query.ts
  • packages/query-core/src/queryObserver.ts
  • packages/query-devtools/src/Devtools.tsx
📚 Learning: 2025-11-02T22:52:33.071Z
Learnt from: DogPawHat
Repo: TanStack/query PR: 9835
File: packages/query-core/src/__tests__/queryClient.test-d.tsx:242-256
Timestamp: 2025-11-02T22:52:33.071Z
Learning: In the TanStack Query codebase, the new `query` and `infiniteQuery` methods support the `select` option for data transformation, while the legacy `fetchQuery` and `fetchInfiniteQuery` methods do not support `select` and should reject it at the type level.

Applied to files:

  • packages/query-core/src/queryObserver.ts
  • packages/query-devtools/src/Devtools.tsx
📚 Learning: 2025-09-02T17:57:33.184Z
Learnt from: TkDodo
Repo: TanStack/query PR: 9612
File: packages/query-async-storage-persister/src/asyncThrottle.ts:0-0
Timestamp: 2025-09-02T17:57:33.184Z
Learning: When importing from tanstack/query-core in other TanStack Query packages like query-async-storage-persister, a workspace dependency "tanstack/query-core": "workspace:*" needs to be added to the package.json.

Applied to files:

  • packages/query-devtools/src/Devtools.tsx
🔇 Additional comments (3)
packages/query-core/src/query.ts (2)

390-406: Comment typo fix is fine (retryer).
No behavior change; the guard still reads correctly.


736-740: Good removal of the unnecessary cast around initialDataUpdatedAt() call.
Keeps intent clear and should still type-narrow correctly via the typeof === 'function' check.

packages/query-core/src/queryObserver.ts (1)

335-346: Passing this.options into Query.fetch directly looks correct.
Assuming QueryObserverOptions structurally contains QueryOptions (it should), this keeps types simpler without changing runtime behavior.

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.

1 participant