I have an object that I need to type, but am unsure how to do this. The following is the error I am seeing and my code is below.
Element implicitly has an 'any' type because type '{ LIV: string; MAN: string; LDN: string; }' has no index signature. [7017]
type Props = {
city: string;
cityMap: {
LIV: string;
MAN: string;
LDN: string;
};
};
const Cities = ({ city }: Props) => {
const cityMap = {
LIV: 'Liverpool',
MAN: 'Manchester',
LDN: 'London'
};
const city = cityMap[city];
return <>{city}</>;
};