typescript 类型兼容问题

interfaceSelect{
lable:string,
value:string[]
}
interfaceInput{
lable:string
value:string
}
constarr=[
{
lable:"select",
value:['boy','gril']
},
{
lable:'input',
value:'thisisainput'
}
];
arr.forEach((item:Select|Input)=>{
if(item.lable=='input'){
reciverInputProps(item.value)
}else{
reciverSelectProps(item.value)
}
})
functionreciverInputProps(value:string){
}
functionreciverSelectProps(value:[]){
}
现在我定义了两个interface,他们之间的value类型不一样,一个是string,另一个是数组但是我需要在forEach里面根据lable的类型分别传值另外两个函数,这两个函数的参数类型不一样,编辑器会提示报错,有什么办法兼容不同的类型吗
偶然的你
浏览 501回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript