In yup's doc I could not find anything for validating tuple arrays and alternative objects. How would an object like this be validated in yup?
interface Example {
tuple: string[]; // always two elements
alt: { foo: string; } | { bar: string; }
}
For alternative objects/types you can use yup.lazy():
yup.lazy((alt: { foo: string; } | { bar: string; }) => {
if (alt.foo) return yup.object<{ foo: string; }>();
if (alt.bar) return yup.object<{ bar: string; }>();
})
For tuples, this answer is the best help I could find, but it does not wok in typescript: https://github.com/jquense/yup/issues/528#issuecomment-496353532
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.