我正在为下面的对象编写一个类型。此对象是API调用的结果。
概述
现在data.25924上的属性是未知的,或者基本上数字25924是动态的,它可以是字面上的任何东西,但对象的形状保证是相同的。
到目前为止我的情况是
export type HotelImagesType = {
categories: never[];
data: {
[key: string]: [
number,
{
tag_type: string;
tag_name: string;
tag_id: number;
photo_id: number;
confidence: number;
}[],
number,
{
id: number;
tag: string;
}[],
string,
string,
string,
string
][];
};
url_prefix: string;
};
我不确定上面的代码是否有效,因为当我尝试将类型分配给JSON格式的确切对象(因此VScode推断类型)时,我得到一个错误
属性“25924”与索引签名不兼容。然后深入堆栈跟踪另一个错误目标需要8个元素,但源可能需要更少的元素
下面是Json对象的一个小表示
{
"categories": [],
"data": {
"25924": [
[
1,
[
{
"tag_type": "ml_tags",
"tag_name": "Bathroom",
"confidence": 100,
"tag_id": 11,
"photo_id": 222277711
},
{
"tag_type": "ml_tags",
"tag_name": "Kitchen/Kitchenette",
"tag_id": 6,
"confidence": 90,
"photo_id": 222277711
}
],
222277711,
[
{
"id": 153,
"tag": "Bathroom"
},
{
"tag": "Property",
"id": 1000000001
}
],
"/xdata/images/hotel/max1024x768/222277711.jpg?k=07017d55d465e5398bc7da202e3cd3e65ff380983708c00b77930d0345342b1a&o=",
"/xdata/images/hotel/max300/222277711.jpg?k=07017d55d465e5398bc7da202e3cd3e65ff380983708c00b77930d0345342b1a&o=",
"/xdata/images/hotel/max500/222277711.jpg?k=07017d55d465e5398bc7da202e3cd3e65ff380983708c00b77930d0345342b1a&o=",
"/xdata/images/hotel/square60/222277711.jpg?k=07017d55d465e5398bc7da202e3cd3e65ff380983708c00b77930d0345342b1a&o="
],
[
1,
[
{
"confidence": 97,
"tag_id": 19,
"photo_id": 5759899,
"tag_name": "Property Building",
"tag_type": "ml_tags"
}
],
5759899,
[
{
"id": 3,
"tag": "Property building"
},
{
"tag": "Day",
"id": 41
},
{
"tag": "Property",
"id": 1000000001
}
],
"/xdata/images/hotel/max1024x768/5759899.jpg?k=a8edb6c0c2938bb31d4f27dd62325249531f16faa3fe4b8f27bd095d1e6eedfb&o=",
"/xdata/images/hotel/max300/5759899.jpg?k=a8edb6c0c2938bb31d4f27dd62325249531f16faa3fe4b8f27bd095d1e6eedfb&o=",
"/xdata/images/hotel/max500/5759899.jpg?k=a8edb6c0c2938bb31d4f27dd62325249531f16faa3fe4b8f27bd095d1e6eedfb&o=",
"/xdata/images/hotel/square60/5759899.jpg?k=a8edb6c0c2938bb31d4f27dd62325249531f16faa3fe4b8f27bd095d1e6eedfb&o="
]
]
},
"url_prefix": "https://cf.bstatic.com"
}
1条答案
按热度按时间r7xajy2e1#
使用
any
作为类型。比如说
variableName: any;
variableName = any