-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
TypeScript Version: 2.5.3
It could be I stumbled on something I simply don't understand, but it seems like this should work:
Code
enum Color {
RED = "RED",
BLUE = "BLUE",
GREEN = "GREEN"
}
type ColorMap = {
[P in Color]: number; // type ColorMap = { RED: number; BLUE: number; GREEN: number; }
}
declare const color: Color;
map[color] // Error: Element implicitly has an 'any' type because type 'ColorMap' has no index signature.All of the following work:
declare const map: ColorMap;
map[Color.RED] // OK
const red: Color = Color.RED;
map[red] // OK
declare const color: keyof typeof Color;
map[color] // OK -- I don't know why this worksExpected behavior:
map[color] to work and give return type of number
Actual behavior:
map[color] // Error: Element implicitly has an 'any' type because type 'ColorMap' has no index
aluanhaddad
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created