ianstormtaylor / superstruct

A simple and composable way to validate data in JavaScript (and TypeScript).
https://docs.superstructjs.org
MIT License
7.01k stars 224 forks source link

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

Open andreisaikouski opened 1 year ago

andreisaikouski commented 1 year ago

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;
}
jakubwolny commented 1 year ago

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

andreisaikouski commented 1 year ago

@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()