For AI agents: the complete documentation index is available at https://heyq02.com/llms.txt, the full documentation bundle is available at https://heyq02.com/llms-full.txt, and this page is available as Markdown at https://heyq02.com/blog/posts/typescript-multidimensional-arrays.md.
跳到主要内容

TS 中奇怪的多维数组

预计阅读时间: 小于 1 分钟

作为 JS 的超集,TS 严格的类型规定大部分时候能大大提高我们的编程效率,但是有时候也会出现很麻烦的场景。

问题情景

TS 中创建数组需要用到泛型,我们以一维数组为例:

const arr: Array<number> = []

arr[0] = 1

console.log(arr)
// [1]

然而对于二维数组却有一个很有意思的问题。