CallerComponent
compiles to the dictionary like {HOMEPAGE: "homepage", DEFAULT: "default"}
. What is why CallerComponent["homepage"] is undefined
.
And "homepage" === CallerComponent.HOMEPAGE
.
So, I 'm confused. What do you want to achieve?
UPD: Ah, I get it. I guess you tried to get a key name by the value? It works this way with regular enums, not string ones.
export enum CallerComponent {
HOMEPAGE,
DEFAULT
}
const keyName = CallerComponent[CallerComponent.HOMEPAGE]; // HOMEPAGE
More information is here: https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings
Keep in mind that string enum members do not get a reverse mapping generated at all.
So if you really would like to reverse it by some reasons, you could play around the underlying dictionary, as you usually do in plain javascript