TanStack / TanStack/router

data type not inferred from validator when method: 'GET' in createServerFn (regression in @tanstack/react-start 1.168.24)

Open
#7,671 0 comments 0 reactions 0 assignees View on GitHub

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
  1. Create a server function with method: 'GET'
  2. Chain .validator() with any validator (zod schema, function)
  3. Access ctx.data inside .handler() — TypeScript reports the type as unknown
Expected behavior

ctx.data should be typed as { id: string } (i.e., the output type inferred from the validator).

Screenshots or Videos
Image
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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.