form icon indicating copy to clipboard operation
form copied to clipboard

2nd function argument of `serverValidate` should be in type `FormDataInfo | FormDataTransform` instead of `Parameters<typeof decode>[1]`

Open mwskwong opened this issue 10 months ago • 1 comments

Describe the bug

https://github.com/TanStack/form/blob/a1568ff667ef6afe8aff576bdc1079327701a6de/packages/react-form/src/nextjs/createServerValidate.ts#L69

Since decode() has two definitions (simplified):

declare function decode(formData: FormData, info: FormDataInfo, transform?: FormDataTransform): TOutput;
declare function decode(formData: FormData, transform?: FormDataTransform): TOutput;

Specifying Parameters<typeof decode>[1] will result in FormDataTransform, while it is perfectly fine to specify FormDataInfo in this case. In fact, the variable name info is likely initially intended for the latter.

Your minimal, reproducible example

https://codesandbox.io/p/devbox/dpnwf9?file=%2Fapp%2Factions.ts%3A6%2C42

Steps to reproduce

  1. Create a serverValidate function by using createServerValidate according to the doc
  2. Attempt to add a 2nd arg when calling the function
  3. Observe the TS error

Expected behavior

The 2nd arg of serverValidate() should support both FormDataInfo and FormDataTransform, according to the definition of decode()

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

N/A

TanStack Form adapter

react-form

TanStack Form version

v1.2.4

TypeScript version

v5.8.2

Additional context

No response

mwskwong avatar Apr 04 '25 08:04 mwskwong