Typescript offers tuple types that enable the declaration of an array with a specific length and type constraints:
let arr: [number, number, number];
arr = [1, 2, 3]; // valid
arr = [1, 2]; // Error: Type '[number, number]' is not assignable to type '[number, number, number]'
arr = [1, 2, "3"]; // Error: Type '[number, number, string]' is not assignable to type '[number, number, number]'
To define a custom type, you can use something like:
handlers: [{handler: string, modifiers: string[]}, string][]
Another approach is to restrict this type to only apply to the first element:
interface MyInterface {
[index: number]: string[] | [{handler: string, modifiers: string[]}, string];
0: [{handler: string, modifiers: string[]}, string];
}
If the type should only be enforced at the beginning position, consider using Variadic tuple types
type MyType = [[{handler: string, modifiers: string[]}, string], ...string[][]]