[英]typescript interface for specific json
I wonder, how to create ts interface for this kind of JSON:我想知道,如何为这种 JSON 创建 ts 接口:
"Cities": {
"NY": ["New York", [8000, 134]],
"LA": ["Los Angeles", [4000, 97]],
}
I dont knot how to create this nested arrays and unique label.我不知道如何创建这个嵌套数组和唯一标签。
You can declare the elements an array will contains:您可以声明数组将包含的元素:
interface IData {
[key: string]: [
string,
[number, number]
];
}
[number, number]
indicates the array contains exactly 2 elements of type number
. [number, number]
表示数组正好包含 2 个number
类型的元素。 The notation differs from number[]
which indicates an array of number
.表示法与
number[]
不同,后者表示number
数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.