索引类型接口,对于新从JavaScript转TypeScript的人来说很容易将interface接口类型的数据当成JavaScript对象来进行索引获取,像这样:
interface IProps {name: stringage: stringcity: string[index: string]: string}const Index: React.FC<IProps> = (props) => {return(<div><p>{props['name']}</p><p>{props['age']}</p><p>{props['city']}</p></div>)}export default Index
interface IProps {
name: string
age: string
city: string
[index: string]: string
}
const Index: React.FC<IProps> = (props) => {
return(
<div>
<p>{props['name']}</p>
<p>{props['age']}</p>
<p>{props['city']}</p>
</div>
)
}
export default Index
function App() {
return (
<div className="App">
<Index name='zhangsan' age='18' city='sh'/>
</div>
);
}

