Typescript recursive types for array of array

I want describe some data as where a value in the array could be another array of numbers, this is done indefinitely so the types should be recursive.

With the following code I receive an error

Type 'number' is not assignable to type 'Data'

type Data = ReadonlyArray<number> | Data[];
const data: Data = [1, 2, 3, [4, 5, [6, 7]]];

How to fix it using the latest TypeScript?



Read more here: https://stackoverflow.com/questions/67385373/typescript-recursive-types-for-array-of-array

Content Attribution

This content was originally published by Radex at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: