TanStack / TanStack/router

Broken type for useServerFn inside useMutation

Open
#5,352 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

types
Dominant language
TypeScript
Stars
15.1k
Forks
1.9k
Avg merge
1d 20h
Merged PRs (30d)
143

Description

Which project does this relate to?

Router

Describe the bug

Hi, I think the type is broken for the useServerFn.
I've reproduced and noticed that if I need to use the onSuccess callback I loose the types

Your Example Website or App

https://github.com/Christopher96u/ts-issue-demo

Steps to Reproduce the Bug or Issue
  1. Go to the index/home route
Expected behavior

I expect as user, to have the onSuccess types back or improve the docs if this is the right behaviour

Screenshots or Videos

If I comment out the onSuccess callback there is no TS issues

Image

If I leave the onSuccess callback there is a TS issue

Image

If we use the useServerFn hook at top level (not inside the useMutation hook, we get the types back

Image
Platform
  • Router / Start Version: [e.g. 1.121.0]
  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Browser Version: [e.g. 91.1]
  • Bundler: [e.g. vite]
  • Bundler Version: [e.g. 7.0.0]
Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the index/home route in the linked ts-issue-demo reproduction and inspect how useServerFn is passed into useMutation, especially the onSuccess callback. Compare that with using useServerFn at the top level. Done means the callback types are preserved, or the documentation clearly explains the intended behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.