Skip to content

Conversation

jinseoIT
Copy link
Contributor

@jinseoIT jinseoIT commented Oct 14, 2025

🎯 Changes

This PR removes a duplicated conditional branch in the MutationKey type definition.

Previously, Array<unknown> was checked twice, which caused redundant type logic.

// Before
? TMutationKey extends Array<unknown>
  ? TMutationKey
   : TMutationKey extends Array<unknown>
     ? TMutationKey
     : ReadonlyArray<unknown>
: ReadonlyArray<unknown>

// After
? TMutationKey extends Array<unknown>
   ? TMutationKey
   : ReadonlyArray<unknown>
: ReadonlyArray<unknown>

✅ 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

  • Refactor
    • Simplified type resolution logic for mutation keys by reordering conditional checks.
    • Removes a redundant condition in type handling and clarifies which array forms are matched.
    • No runtime or behavioral changes; IDE/type-checking clarity improved.
    • No breaking changes expected.

Copy link

changeset-bot bot commented Oct 14, 2025

🦋 Changeset detected

Latest commit: bbb0bc2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
@tanstack/query-core Patch
@tanstack/angular-query-experimental Patch
@tanstack/query-async-storage-persister Patch
@tanstack/query-broadcast-client-experimental Patch
@tanstack/query-persist-client-core Patch
@tanstack/query-sync-storage-persister Patch
@tanstack/react-query Patch
@tanstack/solid-query Patch
@tanstack/svelte-query Patch
@tanstack/vue-query Patch
@tanstack/angular-query-persist-client Patch
@tanstack/react-query-persist-client Patch
@tanstack/solid-query-persist-client Patch
@tanstack/svelte-query-persist-client Patch
@tanstack/react-query-devtools Patch
@tanstack/react-query-next-experimental Patch
@tanstack/solid-query-devtools Patch
@tanstack/svelte-query-devtools Patch
@tanstack/vue-query-devtools Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Contributor

coderabbitai bot commented Oct 14, 2025

Walkthrough

Reorders the conditional checks in the MutationKey type in packages/query-core/src/types.ts so a provided TMutationKey is first tested as ReadonlyArray<unknown>, then as Array<unknown>, otherwise falls back to ReadonlyArray<unknown>. Adds a changeset bump for @tanstack/query-core.

Changes

Cohort / File(s) Change Summary
Type change
packages/query-core/src/types.ts
Reordered conditional branches in the MutationKey type: now checks ReadonlyArray<unknown> before Array<unknown>, preserving the fallback to ReadonlyArray<unknown>.
Release metadata
.changeset/chilled-squids-grow.md
Patch version bump for @tanstack/query-core and note describing the type-level change to MutationKey.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble at types in moonlit code,
Swapping branches down the rabbit road.
Readonly first, then mutable play,
A tidy burrow for arrays today.
Hooray — I hop back to my node! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "fix(types): remove duplicate Array condition in MutationKey type" clearly and accurately describes the main change in the pull request. The title directly corresponds to what is documented in the PR description, which explains the issue of a duplicated Array<unknown> condition in the MutationKey type definition and shows a before/after code snippet demonstrating the simplification. The title is concise, specific, and would allow a teammate scanning the commit history to quickly understand the primary purpose of the change.
Description Check ✅ Passed The PR description follows the required template structure with all three main sections present and completed. The 🎯 Changes section provides a clear explanation of the issue (duplicate Array condition), includes before/after code snippets showing the simplification, and explains the motivation. The ✅ Checklist section has both required items checked (Contributing guide followed and local tests run). The 🚀 Release Impact section is included with both checkboxes present, though neither is selected. The description is well-organized and provides sufficient context for understanding the change.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

nx-cloud bot commented Oct 16, 2025

View your CI Pipeline Execution ↗ for commit bbb0bc2

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 4m 2s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 24s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-16 11:50:32 UTC

Copy link

pkg-pr-new bot commented Oct 16, 2025

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@9754

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@9754

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@9754

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@9754

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@9754

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@9754

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@9754

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@9754

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@9754

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@9754

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@9754

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@9754

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@9754

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@9754

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@9754

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@9754

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@9754

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@9754

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@9754

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@9754

commit: bbb0bc2

Copy link

codecov bot commented Oct 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.80%. Comparing base (969801c) to head (bbb0bc2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #9754       +/-   ##
===========================================
+ Coverage   45.75%   59.80%   +14.05%     
===========================================
  Files         200      129       -71     
  Lines        8403     5618     -2785     
  Branches     1928     1527      -401     
===========================================
- Hits         3845     3360      -485     
+ Misses       4111     1954     -2157     
+ Partials      447      304      -143     
Components Coverage Δ
@tanstack/angular-query-experimental 93.85% <ø> (ø)
@tanstack/eslint-plugin-query ∅ <ø> (∅)
@tanstack/query-async-storage-persister 43.85% <ø> (ø)
@tanstack/query-broadcast-client-experimental 24.39% <ø> (ø)
@tanstack/query-codemods ∅ <ø> (∅)
@tanstack/query-core 97.48% <ø> (ø)
@tanstack/query-devtools 3.48% <ø> (ø)
@tanstack/query-persist-client-core 80.00% <ø> (ø)
@tanstack/query-sync-storage-persister 84.61% <ø> (ø)
@tanstack/query-test-utils ∅ <ø> (∅)
@tanstack/react-query 96.01% <ø> (ø)
@tanstack/react-query-devtools 10.00% <ø> (ø)
@tanstack/react-query-next-experimental ∅ <ø> (∅)
@tanstack/react-query-persist-client 100.00% <ø> (ø)
@tanstack/solid-query 78.06% <ø> (ø)
@tanstack/solid-query-devtools 61.90% <ø> (ø)
@tanstack/solid-query-persist-client 100.00% <ø> (ø)
@tanstack/svelte-query ∅ <ø> (∅)
@tanstack/svelte-query-devtools ∅ <ø> (∅)
@tanstack/svelte-query-persist-client ∅ <ø> (∅)
@tanstack/vue-query 71.10% <ø> (ø)
@tanstack/vue-query-devtools ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

🧹 Nitpick comments (1)
packages/query-core/src/types.ts (1)

1073-1079: Optional: de-duplicate QueryKey/MutationKey logic via a helper type

To keep these in lockstep, consider extracting the conditional once:

type KeyFromRegister<P extends 'queryKey' | 'mutationKey'> =
  Register extends { [K in P]: infer TKey }
    ? TKey extends ReadonlyArray<unknown>
      ? TKey
      : TKey extends Array<unknown>
        ? TKey
        : ReadonlyArray<unknown>
    : ReadonlyArray<unknown>

export type QueryKey = KeyFromRegister<'queryKey'>
export type MutationKey = KeyFromRegister<'mutationKey'>
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2905262 and 8574491.

📒 Files selected for processing (1)
  • packages/query-core/src/types.ts (1 hunks)
🔇 Additional comments (1)
packages/query-core/src/types.ts (1)

1073-1079: LGTM: MutationKey now mirrors QueryKey and removes the redundant branch

Checks ReadonlyArray first, then Array, else falls back to ReadonlyArray — identical to QueryKey. This addresses the prior review ask and keeps behavior consistent.

Per previous review comment.

@TkDodo TkDodo merged commit 20ef922 into TanStack:main Oct 16, 2025
9 checks passed
This was referenced Oct 16, 2025
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.

3 participants