是否有可能在接口中定义变量只能等于字符串数组中的字符串,当数组非常大并且使用union类型似乎不可行时?
我有一个国家代码列表,如['US','GB','CY','PL']等,总共约200个。
是否可以像
那样做interface ICountryInfo {
countryCode: CountryCodes;
}
CountryCodes
是一个代码数组?
答案 0 :(得分:0)
您可以使用枚举类型来定义CountryCodes。
enum CountryCodes{
US,
GB,
CY,
PL
}
interface ICountryInfo {
countryCode: CountryCodes;
}