In my code, I am using an enum as a propName for an object-like type.
export enum WeaponClass {
smallLaser = "smallLaser",
}
export type WeaponType = {
[propName in WeaponClass]: number
};
const weapons: WeaponType = {
[WeaponClass.smallLaser]: 1,
};
Check out the playground for this code snippet
I am curious if it is possible to use a generic for the propName and pass in an enum. However, when I tried this approach, it resulted in errors.
export enum WeaponClass {
smallLaser = "smallLaser",
}
export type WeaponType<T> = {
[propName in T]: number
};
const weapons: WeaponType<WeaponClass> = {
[WeaponClass.smallLaser]: 1,
};