Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

273
Visualizações
validate either object with Yup

I'm trying to validate an object, which is an union type of two objects. It's like two different subforms where you can fill either of them or both, but it shouldn't be empty

here's a simplified example:

// it's valid if it has all of the fields of the first sub-form
const valid1 = {
  a: "a",
  b: "b",
  c: "c"
};

// it's valid if it has all of the fields of the second sub-form
const valid2 = {
  d: "a",
  e: "b",
  f: "c"
};

// it's valid if it has all of the fields of both sub-forms
const valid3 = {
  ...valid1,
  ...valid2
};

// it's invalid if it's empty or has only one sub-form field

const invalid1 = {
  ...valid1,
  e: "b"
};

const invalid2 = {
  ...valid2,
  a: "a"
};

const invalid3 = {};

here's a sandbox setup with all of my attempts so far

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda