【发布时间】:2021-08-29 09:53:15
【问题描述】:
有人可以帮我解决以下问题吗?
type Item = {
id: number;
size: number;
}
type Example = {
name: string;
items: [
Item
];
}
var obj: Example = {
name: "test",
items: [
{
id: 1,
size: 10
},
{
id: 2,
size: 34
}
]
}
其实 items 应该是 Item 类型的列表,但我遇到了错误。
输入 '[{ id: number;尺寸:数量; }, { 身份证号码;尺寸:数量; }]' 不可分配给类型“[项目]”。源有 2 个元素,但 target 只允许 1.(2322)
【问题讨论】:
-
试试吧:
type Example = { name: string; items:Item []; }
标签: javascript reactjs typescript react-native