{"id":191,"hash":"e7a127611793333fa4c74c2ed78a0713c6e64c2b408f3bd467f8326c7fdb44d2","pattern":"An index signature parameter type cannot be a union type. Consider using a mapped object type instead","full_message":"I'm trying to use the following pattern:\n\nenum Option {\n  ONE = 'one',\n  TWO = 'two',\n  THREE = 'three'\n}\n\ninterface OptionRequirement {\n  someBool: boolean;\n  someString: string;\n}\n\ninterface OptionRequirements {\n  [key: Option]: OptionRequirement;\n}\n\nThis seems very straightforward to me, however I get the following error:\n\n  An index signature parameter type cannot be a union type. Consider using a mapped object type instead.\n\nWhat am I doing wrong?","ecosystem":"npm","package_name":"typescript","package_version":null,"solution":"You can use TS \"in\" operator and do this:\n\nenum Options {\n  ONE = 'one',\n  TWO = 'two',\n  THREE = 'three',\n}\ninterface OptionRequirement {\n  someBool: boolean;\n  someString: string;\n}\ntype OptionRequirements = {\n  [key in Options]: OptionRequirement; // Note the \"in\" operator.\n}\n\nMore about the in operator","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/54438012/an-index-signature-parameter-type-cannot-be-a-union-type-consider-using-a-mappe","votes":616,"created_at":"2026-04-19T04:41:29.537806+00:00","updated_at":"2026-04-19T04:51:11.499036+00:00"}