Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling createFormFactory<FormData> and using a validator adapter throw TS errors #669

Closed
timfee opened this issue Apr 6, 2024 · 1 comment

Comments

@timfee
Copy link

timfee commented Apr 6, 2024

Describe the bug

I had to pass typeof zodValidator as a second type param for validatorAdapter to not throw a TS warning.

Your minimal, reproducible example

export type FormSchema = { id: string } 

export const formFactory = createFormFactory<FormSchema>({
  validatorAdapter: zodValidator,
// ...

Expected behavior

I didn't expect the following error:

Type 'ZodString' is not assignable to type 'FieldValidateFn<Partial<{ slug: string; url: string; is_locked: boolean; is_public: boolean; id?: string | undefined; }>, "slug", undefined, undefined, string | undefined>'.

Type 'ZodString' provides no match for the signature '(props: { value: string | undefined; fieldApi: FieldApi<Partial<{ slug: string; url: string; is_locked: boolean; is_public: boolean; id?: string | undefined; }>, "slug", undefined, undefined, string | undefined>; }): ValidationError'.

It wasn't until I added the second type param: createFormFactory<FormSchema, typeof zodValidator> that it went away.

(I'm not sure if that's technically correct or the desired DX :))

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

react + ts

TanStack Form adapter

react-form

TanStack Form version

0.19.0

TypeScript version

5.4.4

Additional context

No response

@crutchcorn
Copy link
Member

This is almost a dupe of #610, but heads up that you should not provide the default type and expect inferencing (say, of the validator) to still run. This is a limitation of TS, not our library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants