Javascript yup模式验证-元组和替代对象

Javascript yup模式验证-元组和替代对象,javascript,node.js,typescript,validation,yup,Javascript,Node.js,Typescript,Validation,Yup,在yup的文档中,我找不到任何用于验证元组数组和替代对象的内容。在yup中如何验证这样的对象 interface Example { tuple: string[]; // always two elements alt: { foo: string; } | { bar: string; } } 对于其他对象/类型,可以使用yup.lazy(): yup.lazy((alt:{foo:string;}{bar:string;})=>{ if(alt.foo)返回yup.obj

在yup的文档中,我找不到任何用于验证元组数组和替代对象的内容。在yup中如何验证这样的对象

interface Example {
    tuple: string[]; // always two elements
    alt: { foo: string; } | { bar: string; }
}

对于其他对象/类型,可以使用yup.lazy():

yup.lazy((alt:{foo:string;}{bar:string;})=>{
if(alt.foo)返回yup.object();
if(alt.bar)返回yup.object();
})
对于元组,这个答案是我能找到的最好的帮助,但它在typescript中不起作用:

yup.lazy((alt: { foo: string; } | { bar: string; }) => {
    if (alt.foo) return yup.object<{ foo: string; }>();
    if (alt.bar) return yup.object<{ bar: string; }>();
})