我试图枚举映射到一个字符串:枚举到字符串查找对象 - >没有索引签名
enum Status {
NEW = "NEW",
INPROCESSING = "IN PROCESSING",
DONE = "DONE"
};
const statusToColor: { [key in Status ]: string } = {
"NEW": "blue",
"IN PROCESSING": "yellow",
"DONE": "green"
}
到现在为止一切都很好。 但当我尝试:
编辑:似乎我简化了问题太多,作为实际问题似乎仍然是别的地方:
的没有索引错误只发生,当我尝试从数组喂 “statusToColor”,是这样的:
const statusArrayToColors = (statusArray: Status[]): string[] => {
return statusArray.map(status => statusToColor[status])
}
在这种情况下
statusToColor[status]
根据编译器没有索引签名。
您是否看到我的答案?你编辑修改错字的代码适合我。 – lilezek