Skip to content

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

Description

@motopods

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions