According to the information provided in the Handbook, it is possible to define a custom array interface with either string or number index:
interface StringArray {
[index: number]: string;
}
To demonstrate this concept, I created the following interface:
interface EventRegistrations {
[index:string]:ListenerEntry[];
}
The issue at hand is fairly straightforward: how does one initialize such a structure?
Below are my attempts, along with the corresponding error messages (I am using PhpStorm 2016.1 with tsc 1.8.7):
foo:EventRegistrations = [];
Type 'undefined[]' is not compatible with type 'EventRegistrations'
foo:EventRegistrations = [[]];
Type 'undefined[][]' is not compatible with type 'EventRegistrations'
foo:EventRegistrations = [index:string]:ListenerEntry[];
Syntax error (expected , instead of the first :)
foo:EventRegistrations = [string]:ListenerEntry[];
Syntax error (expected ; instead of the second :)
foo:EventRegistrations = new EventRegistrations();
Syntax error (unable to locate name 'EventRegistrations')