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的類型分別傳值另外兩個函數,這兩個函數的參數類型不一樣,編輯器會提示報錯,有什么辦法兼容不同的類型嗎
typescript 類型兼容問題
楊__羊羊
2019-03-25 10:41:23