Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

275
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda