Sorry for creating another question of this type but even though there are similar ones I am not able to apply theirs solutions to my particular case.
Can someone please help me handle this TypeScript error?
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Record<RouteName, TranslatableRoute>'.
No index signature with a parameter of type 'string' was found on type 'Record<RouteName, TranslatableRoute>'.(7053)
I am looking for the right way how to solve it not some workaround by destroying type safety. Here is some dummy example of where I hit the problem.
type RouteName = 'home' | 'account'
interface TranslatableRoute {
cs: string;
en: string;
}
const translatableRoutes: Record<RouteName, TranslatableRoute> = {
home: {
cs: '/',
en: '/'
},
account: {
cs: '/ucet',
en: '/account'
}
}
const findRoute = '/ucet'
const findLang = 'cs'
for (const key in translatableRoutes) {
if (translatableRoutes[key][findLang] === findRoute) {
console.log(`Found route\'s name is "${key}"!`)
}
}
Typescript playground link.