Reputation: 15583
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?
Upvotes: 0
Views: 105
Reputation: 311865
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"]
];
Upvotes: 3