TypeScript Version: 2.4.1
Code
enum Name {
Fred, Vilma
}
type Names = keyof typeof Name; // type Names = "Fred" | "Vilma";
type Data = ...;
const data: { [name in Names]: Data } = {
Fred: { ... },
Vilma: { ... },
}
function getData(name: Names) {
return data[strName]; // error here
}
Expected behavior:
No error
Actual behavior:
Compilation error message:
Element implicitly has an 'any' type because type '{ readonly Fred: Data; readonly Vilma: Data; ...' has no index signature.
can be fixed by casting data to any or to { [name: string]: Data } before using indexer