data type not inferred from validator when method: 'GET' in createServerFn (regression in @tanstack/react-start 1.168.24)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 15.1k
- Forks
- 1.9k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 143
Description
Which project does this relate to?
Start
Describe the bug
When using createServerFn with method: 'GET' and a .validator(), the data parameter inside the .handler() callback is not correctly typed from the validator's output — it falls back to undefined instead of the expected inferred type.
This is a regression introduced in @tanstack/react-start@1.168.24.
Reproduction
import { createServerFn } from '@tanstack/react-start'
import { z } from 'zod'
const schema = z.object({ id: z.string() })
const myFn = createServerFn({ method: 'GET' })
.validator(schema)
.handler((ctx) => {
// ❌ ctx.data is typed as `unknown` instead of `{ id: string }`
console.log(ctx.data.id)
})
The same pattern works correctly with method: 'POST', or worked correctly with method: 'GET' prior to version 1.168.24.
Package version
@tanstack/react-start:1.168.24
Complete minimal reproducer
SEE DESCRIBE
Steps to Reproduce the Bug
- Create a server function with
method: 'GET' - Chain
.validator()with any validator (zod schema, function) - Access
ctx.datainside.handler()— TypeScript reports the type asunknown
Expected behavior
ctx.data should be typed as { id: string } (i.e., the output type inferred from the validator).
Screenshots or Videos
Platform
- Router / Start Version: 1.168.24
- OS: windows
- Browser: Edge
- Browser Version: 149.0.4022.69
- Bundler: vite
- Bundler Version: 8.0.16
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue in a minimal TypeScript project using createServerFn, method: 'GET', and the validator shown in the report; compare the inferred ctx.data type with the POST case. Trace the createServerFn, validator, and handler type definitions, then verify that the validator output is preserved for GET handlers and that the reproduction type-checks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100