Why do I get this error? How do I give languages an interface when its a object literal in another external module?
Element implicitly has an any
type because expression of type string
can't be used to index type { en: { title: string; }; es: { title: string; }; fi: { title: string; }; }
.
No index signature with a parameter of type string
was found on type { en: { title: string; }; es: { title: string; }; fi: { title: string; }; }
.ts(7053)
export const languages = {
en: {
title: "English"
},
es: {
title: "Español"
},
fi: {
title: "Suomalainen"
}
}
import React from 'react';
import { languages } from './utils/languageData'
interface IProps {
lang: string
}
function LanguageSelect(props: IProps) {
const { lang } = props
const getText = (langId: string, propVal: string): string => {
const result = languages[langId][propVal]
const txt = result ? 'error' : result
return txt
}
return (
<div className="LanguageSelect" data-test="languageSelect-box">
<div className="languageArea">{getText(lang, 'title')}</div>
</div>
);
}
export default LanguageSelect;