![](/img/trans.png)
[英]What would an interface to describe an array of ASP.NET Modelstate look like in Typescript?
[英]How would an typescript interface for this object look like?
我有一个对象数组,我需要为它创建一个接口? 对象数组:
[
{
"_id": "62bd5fba34a8f1c90303055c",
"index": 0,
"email": "mcdonaldholden@xerex.com",
"nameList": [
{
"id": 0,
"name": "Wendi Mooney"
},
{
"id": 2,
"name": "Holloway Whitehead"
}
]
},
{
"_id": "62bd5fbac3e5a4fca5e85e81",
"index": 1,
"nameList": [
{
"id": 0,
"name": "Janine Barrett"
},
{
"id": 1,
"name": "Odonnell Savage"
},
{
"id": 2,
"name": "Patty Owen"
}
]
},
我还发送了这个 object 作为另一个组件中的道具<SomeComponent componentData = {data} >
由内而外地分解...
interface Name {
id: number;
name: string;
}
interface Entry {
_id: string;
index: number;
email?: string;
nameList: Name[]; // or Array<Name>
}
interface SomeComponentProps {
componentData: Entry[];
}
你可以内联整个东西,但 IMO 看起来很乱
interface SomeComponentProps {
componentData: Array<{
_id: string;
index: number;
email?: string;
nameList: Array<{
id: number;
name: string;
}>;
}>;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.