Next.js Discord

Discord Forum

yup schema error using `is:`

Unanswered
American Chinchilla posted this in #help-forum
Open in Discord
American ChinchillaOP
import * as yup from "yup";

export const ContactFormSchema = yup.object().shape({
  firstName: yup.string().required("Imię jest wymagane"),
  lastName: yup.string().required("Nazwisko jest wymagane"),
  email: yup
    .string()
    .email("Nieprawidłowy e-mail")
    .required("E-mail jest wymagany"),
  phone: yup.string().required("Numer telefonu jest wymagany"),
  clientType: yup
    .mixed()
    .oneOf(Object.values(ClientType))
    .required("Typ klienta jest wymagany"),
  companyName: yup.string().when("clientType", {
    is: ClientType.Firma,
    then: yup.string().required("Nazwa firmy jest wymagana"),
    otherwise: yup.string(),
  }),
  nip: yup.string().when("clientType", {
    is: ClientType.Firma,
    then: yup.string().required("NIP jest wymagany"),
    otherwise: yup.string(),
  }),
  question: yup
    .mixed()
    .oneOf(Object.values(Question))
    .required("Pytanie jest wymagane"),
  carChoice: yup.string().when("question", {
    is: "Wybór samochodu z floty",
    then: yup.string().required("Wybór samochodu jest wymagany"),
    otherwise: yup.string().required("Marka i model samochodu są wymagane"),
  }),
  message: yup.string().required("Treść wiadomości jest wymagana"),
});
i get this error on each is: ...
No overload matches this call.
  Overload 1 of 4, '(keys: string | string[], builder: ConditionBuilder<StringSchema<string | undefined, AnyObject, undefined, "">>): StringSchema<string | undefined, AnyObject, undefined, "">', gave the following error.
    Object literal may only specify known properties, and 'is' does not exist in type 'ConditionBuilder<StringSchema<string | undefined, AnyObject, undefined, "">>'.

0 Replies