[英]Typescript: How do I define interfaces for nested (nested) objects?
See below my current JSON payload:请参阅下面我当前的 JSON 有效负载:
{
"state_1": {
"date": [
{
1000: {
"size": 3,
"count": 0
}
}
{
1001: {
"size": 3,
"count": 1
}
}
}
]
}
How would I set up the definition of the Example interface to model a type state
that has a date
which has a list of id
(here 1000
and 1001
) which are a dictionary holding strings size
and count
.我将如何设置 Example 接口的定义来对类型状态进行建模,该类型
state
的date
具有id
列表(此处为1000
和1001
),这是一个包含字符串size
和count
的字典。
You can use an index signature to handle unknown key definitions.您可以使用索引签名来处理未知的键定义。
interface State {
date: {
[id: number]: {
size: string;
count: string;
}
}[];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.