gpt4 book ai didi

arrays - 在 TypeScript 中声明数组的替代方法

转载 作者:搜寻专家 更新时间:2023-10-30 21:00:27 26 4
gpt4 key购买 nike

我的 Typescript 文件将使用这些声明中的任何一个进行编译。它们等价吗?这些声明数组的方法有名称吗?

interface Foo {
bounds: number[][];
bounds2: [[number, number], [number, number]];
}

我要将 bounds 传递到其中的库采用一个包含两个二元数组的数组。 bounds2 似乎在上面表达得更清楚,但我不确定它是否真的在做同样的事情。

最佳答案

这不是一回事。

bounds 表示 number 数组的数组。

bounds2 表示一种称为元组类型的东西,它类似于更详细的数组描述(具有指定索引上的类型)。在这种情况下,这是一个包含两个元组的元组,它们都包含两个 number

关于arrays - 在 TypeScript 中声明数组的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33879731/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com