TypeScript Version: 2.1.4
exportinterfaceUserInterfaceColors{[indexinUserInterfaceElement]: ColorInfo;}exportinterfaceColorInfo{r: number;g: number;b: number;a: number;}exportenumUserInterfaceElement{ActiveTitleBar=0,InactiveTitleBar=1,}Expected behavior:
No errors will be thrown.
Actual behavior:
index in UserInterfaceElement throws the error Type 'UserInterfaceElement' is not assignable to type 'string'
This is a regression caused by #12425. The change makes sense, but there are very valid use cases for supporting enums in index signatures.
For another use case, in a project I'm working on, we use an enum to list all types of items. We have a function that takes an object with the enum values as keys, and data as values.
functionloadItemData(data: {[indexinItemType]: string}): void;A workaround is to use index: number, but then it's not enforced that you have to use a valid ItemType as a key.
Original Issue: #2491
TypeScript Version: 2.1.4
Expected behavior:
No errors will be thrown.
Actual behavior:
index in UserInterfaceElementthrows the errorType 'UserInterfaceElement' is not assignable to type 'string'This is a regression caused by #12425. The change makes sense, but there are very valid use cases for supporting enums in index signatures.
For another use case, in a project I'm working on, we use an enum to list all types of items. We have a function that takes an object with the enum values as keys, and data as values.
A workaround is to use
index: number, but then it's not enforced that you have to use a valid ItemType as a key.Original Issue: #2491