我正在使用打字稿3.7 鉴于
enum InformationSection {
Education = 'Education label',
Resume = 'Resume label'
}
代码
InformationSection["Education"]
返回“教育标签”,这是有效的声明 但是如果我写
Object.keys(InformationSection).map(x => InformationSection[x])
然后出现以下错误:
Property 'Education label' does not exist on type 'typeof InformationSection'
这是怎么了?
答案 0 :(得分:0)
我发现的唯一方法是欺骗打字稿,使其停止抱怨无效的索引类型
(InformationSection as any)[x]