My challenge involves defining an interface with keys that match a specific enum key type. However, when I attempt to declare this type, I encounter the following error message:
A mapped type may not declare properties or methods.
Below is the code snippet in question:
enum myEnum {
propOne = 'propOne',
propTwo = 'propTwo'
}
export interface myInterface {
[key in myEnum]: anotherInterface;
}
I attempted to specify the type differently as shown below, but encountered a syntax error:
export interface myInterface {
[key in keyof typeof myEnum]: anotherInterface;
}
Even trying to use a regular object instead of an enum resulted in the same error.