I have code like this In one file I have
interface NominativeCaseType {
corn: string;
buckwheat: string;
rice: string;
barley: string;
wheat: string;
}
export const nominativeCase: NominativeCaseType = { // this is Називний Відмінок in Ukrainian language
corn: 'Кукурудза',
buckwheat: 'Гречка',
rice: 'Рис',
barley: 'Ячмінь',
wheat: 'Пшениця',
}
in another file I have
import { nominativeCase } from '../../linguistics/categoriesNames';
export const MainScreen: React.FunctionComponent = () => {
const [category, setCategory] = useState('corn');
return (
<article>
{nominativeCase[category]}
</article>
)
}
and problem is that typescript dont allows me to use {nominativeCase[category]}
. VsCode says
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'NominativeCaseType'.
No index signature with a parameter of type 'string' was found on type 'NominativeCaseType'.ts(7053)
I tryied to google it, but still dont understand how what does it means and how to fix it. I even find solution like this Typescript error: TS7053 Element implicitly has an 'any' type And I change my code to
interface NominativeCaseType {
[key: string]: string;
corn: string;
buckwheat: string;
rice: string;
barley: string;
wheat: string;
}
But I still dont understand what does this error means and what [key: string]: string;
means
Help me please