I'm trying convert a enum structur from [key:value] with value as string to [value:key] structure with this code.
my error is
Element implicitly has an 'any' type because expression of type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | ... 31 more ... | "trimEnd"' can't be used to index type 'typeof Country'.
No index signature with a parameter of type 'number' was found on type 'typeof Country'
key as keyof Country
enumeral
export enum Country {
UnitedStates = 'US',
Afghanistan = 'AF',
AlandIslands = 'AX',
}
code
public countries = Object.keys(Country)
.slice(Object.keys(Country).length / 2)
.map(key => ({
label: key,
key: Country[key as keyof Country],
}));
when value of enum is int this code works.