I have the following object defined:
const routes = {
"/": {},
"/abc": {},
};
Now I want to access one of the objects within routes using the index with a variable name:
const indextoFind = "/abc";
const item = routes[indextoFind];
Typescript throws:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ "/": {}; "/abc": {}; }'. No index signature with a parameter of type 'string' was found on type '{ "/": {}; "/abc": {}; }'.
The index is clearly a string so I don't know why it won't allow me to access an object using a string variable.
Also, this works perfectly fine:
const item = routes["/abc"];