我似乎无法定义具有可变元素的嵌套数组的实际类型,但采用固定格式,如下所示:

 [
        [ [1,[11181, ...]] ],
        [ [1,[111211, ...]] ],
        [ [1,[1111, 123, 123, 123, 123, 123]] ],
        [ [1,[11711, 1323]] ],
        [ [1,[11117, 123]] ],
        [ [1,[15111, 1243]] ],
        [ [1,[164111, 123]] ],
        [ [1,[1111, 121553]] ],
        [ [1,[1121, 12223]] ],

        ...

    ]

我试过 :

private readonly _series:[[[number, number[]]]]

但它不会考虑可变大小。

private readonly _series:Array<Array[number, number[]]>

好的,第一级是任意数量的数组的数组: [ [x,x,x,x,x,x], [ ], [ ], [ ], ... ] 下一个是我写 X 的地方,我们有,任意数量的这种格式的数组:[number, number[ANY NUMBER OF ITEMS]]


[[number, number[]]][] is your answer but that's an unreadable mess.

Let's work through it from the inside out, and alias some names.

An array of numbers of any length:

[11711, 1323] = number[]

That becomes the second element in array where the first element is a number:

[1,[11711, 1323]] = [number, number[]] -- call this NumTuple for clarity

These NumTuples are always the single element in an array:

[ [1, [11711, 1323] ] ] = [NumTuple]

And you have a whole array of them:

[NumTuple][]

type NumTuple = [number, number[]];

const numbers: [NumTuple][] = [
        [ [1,[11181, 123, 123, 123, 123, 123]] ],
        [ [1,[111211,  123, 123, 123, 123, 123]] ],
        [ [1,[1111, 123, 123, 123, 123, 123]] ],
        [ [1,[11711, 1323]] ],
        [ [1,[11117, 123]] ],
        [ [1,[15111, 1243]] ],
        [ [1,[164111, 123]] ],
        [ [1,[1111, 121553]] ],
        [ [1,[1121, 12223]] ],
    ]

Playground Link


is it strictly this example, or are there other edge cases? Right now, it looks like an array, with elements that are a single-element array, that is another array, that contains two elements: a number, and then another array that can contain any length of numbers?

where "..." dots are, it means that more elements can follow, but it should be in this format in all cases. yes as you described it, it may contain any length of numbers in the last array level

I really can't tell what you're looking for. Maybe Array<[[number, [number, number, ...number[]]]]> or Array<[[number, [number, ...number[]]]]>? Could you possibly explicitly define what the format is? I just can't tell what pattern I'm supposed to be picking up from this.

okay, first level is Array of any number of Arrays: [ [x,x,x,x,x,x], [ ], [ ], [ ], ... ] next is where i wrote X there we have, any number of arrays of this format: [number, number[ANY NUMBER OF ITEMS]]

I guess it is Array]>> or Array<[[number, Array]]> typescriptlang.org/play?#code/…