Skip to content

test(solid-query/useMutation): add type tests for generic type inference and callbacks#10495

Merged
sukvvon merged 1 commit intomainfrom
test/solid-query-useMutation-type-tests
Apr 14, 2026
Merged

test(solid-query/useMutation): add type tests for generic type inference and callbacks#10495
sukvvon merged 1 commit intomainfrom
test/solid-query-useMutation-type-tests

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Apr 14, 2026

🎯 Changes

Add type tests for useMutation in solid-query, covering all 4 generics (TData, TError, TVariables, TOnMutateResult), callback type inference (onSuccess, onError, onSettled, onMutate), mutate/mutateAsync types, and Accessor<QueryClient> second argument.

✅ 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

  • Tests
    • Added TypeScript type inference tests to ensure compile-time type safety for the mutation hook, verifying correct type inference for data, errors, parameters, and callback arguments.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

Added a new TypeScript declaration test file for the useMutation hook that verifies compile-time type inference. Tests validate data and error type inference, mutate function parameter types, callback signatures, and optional QueryClient arguments using vitest type assertions.

Changes

Cohort / File(s) Summary
TypeScript Declaration Tests
packages/solid-query/src/__tests__/useMutation.test-d.tsx
New test file with 138 lines of vitest type assertions verifying compile-time inference for useMutation hook, including data/error types, mutate/mutateAsync parameter inference, callback return type propagation, and QueryClient argument handling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A test for types so neat and true,
Where mutations dance in TypeScript's view,
Data, errors, callbacks aligned,
Type safety of the finest kind! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding type tests for useMutation focusing on generic type inference and callbacks.
Description check ✅ Passed The description follows the template structure with complete 'Changes' section and 'Checklist' items marked, though 'Release Impact' correctly identifies this as dev-only.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/solid-query-useMutation-type-tests

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

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 14, 2026

View your CI Pipeline Execution ↗ for commit adb0185

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

☁️ Nx Cloud last updated this comment at 2026-04-14 04:43:55 UTC

@github-actions
Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 14, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@10495

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10495

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: adb0185

@github-actions
Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 11.99 KB (0%)
react minimal 9.02 KB (0%)

Copy link
Copy Markdown
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.

🧹 Nitpick comments (2)
packages/solid-query/src/__tests__/useMutation.test-d.tsx (2)

82-89: Optional cleanup: deduplicate repeated CustomError declaration.

Line 82–89 and Line 109–116 duplicate the same local class. Consider lifting a single shared CustomError test helper in this file to reduce repetition.

Also applies to: 109-116

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/solid-query/src/__tests__/useMutation.test-d.tsx` around lines 82 -
89, Define a single shared CustomError class once in this test file and reuse it
in both tests instead of declaring it twice; remove the local duplicate
declarations in the two test cases (the class named CustomError used in the
"should infer custom TError type" test and the other test) and place one
top-level class declaration (or a helper factory) near the other test helpers so
both tests import/consume the same CustomError symbol.

99-105: Consider asserting all onSettled params for full callback coverage.

Line 99–105 already checks data and error; adding assertions for _variables and _onMutateResult would make this callback test fully symmetrical with the PR objective.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/solid-query/src/__tests__/useMutation.test-d.tsx` around lines 99 -
105, The test for useMutation's onSettled callback only asserts types for data
and error; add type assertions for the remaining parameters by checking
_variables and _onMutateResult inside the onSettled callback to ensure full
coverage: assert _variables has the expected variables type (likely void or the
mutation variables type used by mutationFn) and assert _onMutateResult matches
the onMutate return type (e.g., unknown or specific type), referencing the
useMutation call and the onSettled parameter names (_variables, _onMutateResult)
when adding these expectTypeOf checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/solid-query/src/__tests__/useMutation.test-d.tsx`:
- Around line 82-89: Define a single shared CustomError class once in this test
file and reuse it in both tests instead of declaring it twice; remove the local
duplicate declarations in the two test cases (the class named CustomError used
in the "should infer custom TError type" test and the other test) and place one
top-level class declaration (or a helper factory) near the other test helpers so
both tests import/consume the same CustomError symbol.
- Around line 99-105: The test for useMutation's onSettled callback only asserts
types for data and error; add type assertions for the remaining parameters by
checking _variables and _onMutateResult inside the onSettled callback to ensure
full coverage: assert _variables has the expected variables type (likely void or
the mutation variables type used by mutationFn) and assert _onMutateResult
matches the onMutate return type (e.g., unknown or specific type), referencing
the useMutation call and the onSettled parameter names (_variables,
_onMutateResult) when adding these expectTypeOf checks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8c847047-c406-4e54-b514-280edc55be52

📥 Commits

Reviewing files that changed from the base of the PR and between bc83d37 and adb0185.

📒 Files selected for processing (1)
  • packages/solid-query/src/__tests__/useMutation.test-d.tsx

@sukvvon sukvvon self-assigned this Apr 14, 2026
@sukvvon sukvvon merged commit 2e144da into main Apr 14, 2026
10 checks passed
@sukvvon sukvvon deleted the test/solid-query-useMutation-type-tests branch April 14, 2026 05:22
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