Calling `createFormFactory<FormData>` and using a validator adapter throw TS errors
timfee opened this issue · comments
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
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.