我正在使用一个很久以前定义的遗留变量。
export const constellationNancyRomanTable = [
[0.0000,24.0000,88.0000,'UMi'],
[8.0000,14.5000,86.5000,'UMi'],
[21.0000,23.0000,86.1667,'UMi'],
[18.0000,21.0000,86.0000,'UMi'],
...
]然而,我对Typescript非常陌生,所以我正在考虑将这个变量移植到一个新的基于对象的语法,因为我理解了对象的type定义,但这个数组数组暗示了我。然而,我想知道如何定义这样的类型/接口?
我在想这样的事情:
export interface ConstellationNancyRoman = Array<Array<[number, number, number, string]>>是不是有点正确?
发布于 2021-07-12 19:23:26
现在就差不多了:您只需将它嵌套一个Array to deep,因为您已经在定义您的元组了。这应该可以工作(使用type而不是interface):
export type ConstellationNancyRoman = Array<[number, number, number, string]>;See example on TypeScript playground。
您可以一直使用括号表示法,即使对某些人来说,它可能不像以前那样具有可读性:
export type ConstellationNancyRoman = [number, number, number, string][];https://stackoverflow.com/questions/68346467
复制相似问题