Let's say we have an enum like the following:
export enum HeroActionEnum {
STRIKE = 'strike',
HIDE = 'hide',
RUN = 'fly',
TACKLE = 'tackle',
}
now we create a new class with attributes which have the exact same keys represented in the HeroActionEnum
.
export class Hero {
[HeroActionEnum.STRIKE]: EventEmitter<void>;
[HeroActionEnum.HIDE]: EventEmitter<void>;
[HeroActionEnum.RUN]: EventEmitter<void>;
[HeroActionEnum.TACKLE]: EventEmitter<void>;
...
}
The DRY principle is not happy about this. I would actually like to sum the keys up like:
export class Hero {
[key in HeroActionEnum]: EventEmitter<void>;
...
}
I tried a lot but I got nothing to work so far. Thanks in advance for your help!