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