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: []) {
}現(xiàn)在我定義了兩個(gè)interface,他們之間的value類型不一樣,一個(gè)是string,另一個(gè)是數(shù)組但是我需要在forEach里面根據(jù)lable的類型分別傳值另外兩個(gè)函數(shù),這兩個(gè)函數(shù)的參數(shù)類型不一樣,編輯器會(huì)提示報(bào)錯(cuò),有什么辦法兼容不同的類型嗎
typescript 類型兼容問(wèn)題
慕森王
2019-03-27 20:14:12