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