Skip to content
Source
Sign inSign up
TanStack/form

Type inference from serverValidate is misleading #1438

Opengshahbazian(GitHub profile, opens in a new tab) opened this issue 1 comment

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

  1. LeCarbonator(GitHub profile, opens in a new tab) added labelsv2: needs investigation

  2. Resolved in v2 due to a different approach in server validators. Still an issue in v1.

  3. LeCarbonator(GitHub profile, opens in a new tab) removed labelsv2: needs investigation

  4. LeCarbonator(GitHub profile, opens in a new tab) added labelstype: bug

  5. LeCarbonator(GitHub profile, opens in a new tab) added labelsscope: core

  6. LeCarbonator(GitHub profile, opens in a new tab) added labelsarea: types

Sign in to join this conversation.