interface Select {
lable:string, value:string[]
}interface Input {
lable: string
value :string}const arr =[
{
lable: "select", value:['boy', 'gril']
},
{
lable: 'input', value: 'this is a input'
}
];
arr.forEach((item: Select | Input) => {
if (item.lable =='input') {
reciverInputProps(item.value)
}else {
reciverSelectProps(item.value)
}
})function reciverInputProps(value: string) {
}function reciverSelectProps(value: []) {
}现在我定义了两个interface,他们之间的value类型不一样,一个是string,另一个是数组但是我需要在forEach里面根据lable的类型分别传值另外两个函数,这两个函数的参数类型不一样,编辑器会提示报错,有什么办法兼容不同的类型吗
慕森王
守着一只汪
SMILET
随时随地看视频慕课网APP
相关分类