form icon indicating copy to clipboard operation
form copied to clipboard

can't provide validatorAdapter when using createFormFactory

Open barsikus007 opened this issue 1 year ago • 4 comments

Describe the bug

When I try to specify validatorAdapter in createFormFactory props or formFactory.useForm props, I get these errors:

// createFormFactory
Type '() => { validate({ value }: { value: unknown; }, fn: ZodType<any, ZodTypeDef, any>): ValidationError; validateAsync({ value }: { value: unknown; }, fn: ZodType<any, ZodTypeDef, any>): Promise<...>; }' is not assignable to type 'undefined'.ts(2322)

// formFactory.useForm
Type '() => { validate({ value }: { value: unknown; }, fn: ZodType<any, ZodTypeDef, any>): ValidationError; validateAsync({ value }: { value: unknown; }, fn: ZodType<any, ZodTypeDef, any>): Promise<...>; }' is not assignable to type 'undefined'.ts(2322)

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-form-vycsno

Steps to reproduce

  1. use createFormFactory with zodValidator adapter
  2. you need to specify validatorAdapter in every field now

Expected behavior

no type error

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

WSL 2

Tanstack Form adapter

react-form

TanStack Form version

0.13.6

TypeScript version

5.3.3

Additional context

No response

barsikus007 avatar Feb 29 '24 14:02 barsikus007

I created reproducable example, just use createFormFactory instead of usual form creation: https://stackblitz.com/edit/tanstack-form-vycsno

barsikus007 avatar Feb 29 '24 22:02 barsikus007

Good catch! For now, you can as never to ignore the problem (or something akin) as it should function, but we'll investigate and fix.

Thanks for the detailed report!

crutchcorn avatar Mar 04 '24 23:03 crutchcorn

Good catch! For now, you can as never to ignore the problem (or something akin) as it should function, but we'll investigate and fix.

Thanks for the detailed report!

I dig a bit and find another way to solve this issue:

createFormFactory<Model, typeof zodValidator>

barsikus007 avatar Mar 05 '24 02:03 barsikus007

whoops I duped this :) https://github.com/TanStack/form/issues/669

timfee avatar Apr 08 '24 22:04 timfee