【发布时间】:2019-01-03 18:15:38
【问题描述】:
我有一个需要输入的对象,但不确定如何输入。 以下是我看到的错误,我的代码如下。
元素隐式具有“任何”类型,因为 type '{ LIV: string;男人: 细绳; LDN:字符串; }' 没有索引签名。 [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}</>;
};
【问题讨论】:
标签: javascript reactjs typescript