【发布时间】:2020-09-24 16:00:23
【问题描述】:
我有一个这样的枚举:
export enum Colors {
RED = "RED COLOR",
BLUE = "BLUE COLOR",
GREEN = "GREEN COLOR"
}
您能告诉我如何按值获取枚举键吗?即,我需要通过“BLUE COLOR”并获得“BLUE”。
Colors["BLUE COLOR"] 给出错误Element implicitly has an 'any' type because expression of type '"BLUE COLOR"' can't be used to index type 'typeof Colors'. Property 'BLUE COLOR' does not exist on type 'typeof Colors'.
【问题讨论】:
标签: typescript enums