如何创建一个typescript模式,其中至少有一个道具是联合类型?

如何创建一个typescript模式,其中至少有一个道具是联合类型?,typescript,yup,Typescript,Yup,问题是: import * as yup from 'yup'; interface WithUnion { boolOrString: boolean | string; } const testSchema = yup.object().require().shape<WithUnion>({ boolOrString: yup.mixed().oneOf([yup.boolean().required(), yup.string().require()]) })

问题是:

import * as yup from 'yup';

interface WithUnion {
  boolOrString: boolean | string;
}

const testSchema = yup.object().require().shape<WithUnion>({
  boolOrString: yup.mixed().oneOf([yup.boolean().required(), yup.string().require()])
})

import*作为“是”中的“是”;
与工会的接口{
boolOrString:布尔|字符串;
}
const testSchema=yup.object().require().shape({
boolOrString:yup.mixed().oneOf([yup.boolean().required(),yup.string().require()]))
})
引发以下错误:

Type 'ObjectSchema<object & { boolOrString: BooleanSchema<boolean> | StringSchema<string>; }>' is not assignable to type 'ObjectSchema<{ boolOrString: string | boolean; }>'.
  The types of 'fields.boolOrString' are incompatible between these types.
    Type 'Schema<BooleanSchema<boolean> | StringSchema<string>>' is not assignable to type 'Schema<string | boolean>'.
      Type 'BooleanSchema<boolean> | StringSchema<string>' is not assignable to type 'string | boolean'.
        Type 'BooleanSchema<boolean>' is not assignable to type 'string | boolean'.
          Type 'BooleanSchema<boolean>' is not assignable to type 'string'.
类型“ObjectSchema”不可分配给类型“ObjectSchema”。
“fields.boolOrString”的类型在这些类型之间不兼容。
类型“Schema”不可分配给类型“Schema”。
类型“BooleanSchema | StringSchema”不能分配给类型“string | boolean”。
类型“BooleanSchema”不可分配给类型“string | boolean”。
类型“BooleanSchema”不可分配给类型“string”。
有没有其他办法