superstruct icon indicating copy to clipboard operation
superstruct copied to clipboard

[Feature] `one of` or `or` type

Open andreisaikouski opened this issue 2 years ago • 2 comments

Add a one of or or type link in Joi.or()

e.g. I want to validate that type User has at least one of name or email

interface User {
    tel: number;
    address: string;
    name?: string;
    email?: string;
}

andreisaikouski avatar May 11 '23 17:05 andreisaikouski

wouldn't be enough to create a union of 2 types (one with name required, and other with email required)?

jakubwolny avatar May 26 '23 08:05 jakubwolny

@jakubwolny in my project we have larger interfaces which would require significant code duplication. Currently I accomplished this with a refine that then checks for one or the other, but would be easier like Joi.or()

andreisaikouski avatar Jun 14 '23 17:06 andreisaikouski