0

I am trying to create an array of array of strings, something like this:

let rules : type = [
 ["N"]
 ["N", "N"]
 ["N", "N", "N"]
]

But I couldn't set the type. How can I do this?

1 Answer 1

3

Several options here. The best way to go would be as true arrays of arrays:

let rules : string[][] = [
 ["N"],
 ["N", "N"],
 ["N", "N", "N"]
];

or

let rules : Array<Array<string>> = [
 ["N"],
 ["N", "N"],
 ["N", "N", "N"]
];

You can also type it using single-element tuple types, but that's not really the intended usage of tuple types:

let rules : [string[]] = [
 ["N"],
 ["N", "N"],
 ["N", "N", "N"]
];

or

let rules : [string][] = [
 ["N"],
 ["N", "N"],
 ["N", "N", "N"]
];

or

let rules : [[string]] = [
 ["N"],
 ["N", "N"],
 ["N", "N", "N"]
];
Sign up to request clarification or add additional context in comments.

2 Comments

Or maybe Array<Array<string>>
Or Array<string[]>. Or Array<string>[]. Or [Array<string>]. Or... :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.