TanStack / TanStack/form

Type inference from serverValidate is misleading

Open
#1,438 1 comment 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: types scope: core type: bug v1
Dominant language
TypeScript
Stars
6.7k
Forks
682
Avg merge
5d 18h
Merged PRs (30d)
7

Description

Describe the bug

The type of the response from serverValidate (from a createServerValidate) in the example next server actions app has the age field as number, but if you access age at runtime it will be a string.

Your minimal, reproducible example

https://stackblitz.com/github/tanstack/form/tree/main/examples/react/next-server-actions?embed=1&theme=light&preset=node&file=src/index.tsx

Steps to reproduce
  1. Open stackblitz
  2. Check the type that ts expects for validatedData:
Image
  1. See at runtime that printed age is actually a string:
Image
Expected behavior

I'd expect that the type of validatedData should be remain a FormData since it doesn't actually parse the fields into their typescript types.

Another option could be that all the fields of validatedData are strings?

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

macOS
chrome 135

TanStack Form adapter

None

TanStack Form version

1.6.3

TypeScript version

5.8.2

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 src/index.tsx in the linked next-server-actions StackBlitz example and trace createServerValidate through the serverValidate response type. Compare the declared validatedData type with the runtime age value. Done means the inferred type accurately reflects the returned data, with the expected representation for fields such as age made explicit.

Written by the indexing model from the issue text.

Assessment

Tech stack
next.js, typescript
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.