An index signature parameter type cannot be a union type. Consider using a mapped object type instead

I’m trying to use the following pattern:

enum Option {
  ONE = 'one',
  TWO = 'two',
  THREE = 'three'
}

interface OptionRequirement {
  someBool: boolean;
  someString: string;
}

interface OptionRequirements {
  [key: Option]: OptionRequirement;
}

This seems very straightforward to me, however I get the following error:

An index signature parameter type cannot be a union type. Consider using a mapped object type instead.

What am I doing wrong?

8 Answers
8

Leave a Comment