react-hook-form / resolvers

📋 Validation resolvers: Yup, Zod, Superstruct, Joi, Vest, Class Validator, io-ts, Nope, computed-types, typanion, Ajv, TypeBox, ArkType, Valibot, effect-ts and VineJS
https://react-hook-form.com/
MIT License
1.71k stars 155 forks source link

It is not possible to use your types for Yup validation #624

Open freiserg opened 1 year ago

freiserg commented 1 year ago

Describe the bug How to add a custom type when not all fields are inferred from the form?

To Reproduce Steps to reproduce the behavior:

We use so props:

export type FormValues = {
  account: Account;
  currency: Currency;
  amount: string;
};

Account and Account types have many props.

type Account {
  accountId: string;
  name: string;
  type: Type;
  ...
}

account and currency fields are custom Select components.

We need to check that an element is selected.

const validationSchema = Yup.object().shape({
  account: Yup.object().required('Account is required'),
  currency: Yup.object().required('Currency is required'),
  amount: Yup.string().required('Amount is required.')
});

Codesandbox link (Required) codesandbox link.

Expected behavior The yupResolver function should not complain about the given formSchema.

Shentoza commented 7 months ago

Any updates on this? We also had to downgrade to 3.1.0/couldn't upgrade to latest in our codebase, which is really unfortunate.

pronovaso commented 7 months ago

I have a same problem. When I have some complex type for form, sometimes I have in form values which I dont need for validation and if I have like enum as a type, then is the end. Usually I have as form type graphql input type. In this type can be as type for value null, undefined or type of value. But from yup resolver I hade a little bit another type. Value or null. This maybe is my problem.Something missing in yup validation schema (maybe optional). Now I must downgrade to version 3.1.0.