2

How to set the type for an array like

["string", [”string", ["other string"],["any"]], [”string", ["string”, ["something string"]]], ....]

That is, the depth can be any. Number of arrays after index '0' is also. The main condition, the type under the index '0' must be 'string'.

Artem Skibin
  • 111
  • 4

1 Answers1

1

From Ulad Kasach at https://stackoverflow.com/a/60722301/11745228,

This works:

type ValueOrArray<T> = T | ValueOrArray<T>[];
type NestedStringArray = ValueOrArray<string>;

Or, more directly for your answer:

type StringOrArray = string | StringOrArray[];
type NestedArray = StringOrArray;

Then just type your array with NestedStringArray

coravacav
  • 131
  • 1
  • 1
  • 7
  • I found almost the same thing on your link.type NestedArray = string | [ string, ...NestedArray[] ]; its work.thanks – Artem Skibin Jan 28 '21 at 23:52