- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 536
Open
Labels
Description
Currently the type of the form data seems to be inferred from the default values instead of the validator type. However, the validator is typically more complete/extended and since it's used for validation, it should always result in the correct type...
Currently, when I do something like (using zod in the example):
  const optionsForm = useAppForm({
    defaultValues: { foo: '' },
    validators: {
      onChange: z.object({ foo: z.string().optional() }),
    },
  });
This gives me a ts error, because it says the validation schema has foo as optional, while the default values have it filled in.
Another example with an enum type:
  const optionsForm = useAppForm({
    defaultValues: { foo: 'a' },
    validators: {
      onChange: z.object({ foo: z.enum(['a', 'b'])}),
    },
  });
This gives me a ts error because in the default values foo is infered as string, but the validator only accepts the more narrow 'a' | 'b' as type.
Since useAppForm takes a very large number of generics, manually specifying these isn't really a good alternative.
Zombobot1, jonnny013, viniciusbitt, phuong74200, pedro757 and 30 more