我有一个 prop 看起来像:
{
option1,
option2,
option3,
option4,
general,
otheprops
}
我想要的是使它只有一个选项可以使用在给定的时间我有什么作为类型:
interface MyTypes {
option1: boolean
option2: boolean
option3: boolean
general: boolean
otherprops: string
}
我想做的是:
interface GeneralTypes{
general: boolean
otherprops: string
}
interface Option1Types{
option1: boolean
}
interface Option2Types{
option2: boolean
}
interface Option3Types{
option3: boolean
}
type MyTypes = GeneralTypes & ( Option1Types | Option2Types |Option3Types )
但我得到这个错误
Property 'option1' does not exist on type '(GeneralTypes & Option1) | (GeneralTypes & Option2)| (GeneralTypes & Option3) '
Property 'option2' does not exist on type '(GeneralTypes & Option1) | (GeneralTypes & Option2)| (GeneralTypes & Option3) '
Property 'option3' does not exist on type '(GeneralTypes & Option1) | (GeneralTypes & Option2)| (GeneralTypes & Option3) '
2条答案
按热度按时间az31mfrm1#
下面是我在只需要设置其中一个属性时的发现。
有一个完整的解释here。
yzuktlbb2#