LaVOZs

The World’s Largest Online Community for Developers

'; javascript - Validation check of object? - LavOzs.Com

I am having problem that it is not throwing an error if the payload does not Prop1 OR Prop2

What went wrong?

const payload = {
    Prop3: {
      Field1: 1,
      Field2: 2,
    }
}

if ((!payload.Prop1 && typeof payload.Prop1 === "object") || (!payload.Prop2 && typeof payload.Prop2 === "object")) {
    throw new Error("Must contain Prop1 or Prop2")
}