-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueFixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
TypeScript Version: 2.1.4
export interface UserInterfaceColors {
[index in UserInterfaceElement]: ColorInfo;
}
export interface ColorInfo {
r: number;
g: number;
b: number;
a: number;
}
export enum UserInterfaceElement {
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.
function loadItemData (data: { [index in ItemType]: 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
ChiriVulpes, Spacetech, samirbr, maxlk, StrikeForceZero and 94 more
Metadata
Metadata
Assignees
Labels
CommittedThe team has roadmapped this issueThe team has roadmapped this issueFixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript