TypeScript: "Element implicitly has an 'any' type because expression of type 'string' can't be used to index type"
@devsingh05▲ 10 net votes
Indexing an object literal with an arbitrary string fails under strict mode because TypeScript cannot prove the key exists. Options: type the object as Record<string, Value>; narrow the key to keyof typeof obj (const k = key as keyof typeof obj, after checking key in obj); or use a Map. For lookup tables of known keys, declare the key union explicitly so typos become compile errors.