form icon indicating copy to clipboard operation
form copied to clipboard

Type inference from serverValidate is misleading

Open gshahbazian opened this issue 8 months ago • 0 comments

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

gshahbazian avatar Apr 21 '25 21:04 gshahbazian