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 works
Expected 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
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
All of the following work:
Expected behavior:
map[color]to work and give return type ofnumberActual behavior:
map[color] // Error: Element implicitly has an 'any' type because type 'ColorMap' has no index