The type definition for Map is as follows
interface MapConstructor {
new <K, V>(): Map<K, V>;
new <K, V>(iterable: IterableShim<[K, V]>): Map<K, V>;
prototype: Map<any, any>;
}
I want to use the 2nd constructor new <K, V>(iterable: IterableShim<[K, V]>): Map<K, V>;
I have a type I've defined type ChangeMap = { [key: string]: Array<string> }; which is used as follows
let changeMap: ChangeMap = { A: ["Car", "Boat"], B: ["Plane", "Rocket"] };
I want to create a Map<number, ChangeMap> which I can do easily enough but I'm stuck as to how to structure the data I want to initialize my Map with
public changeOptions = new Map<number, ChangeMap>( ... what goes here ... ?)
Is this possible or do I need to initialize my Map without values and then call changeOptions.set(1, changeMap); to give it values?
--- EDIT #1
To answer @Paarth's question below, the number keys in the changeOptions Map are identifiers for other objects in the domain.
Assume I have a class of Option defined as follows
class Option {
id: number;
name: string;
}
The id of a given Option instance would be the key for the changeOptions Map. There are a limited predefined set of Options based on business rules for the domain. Assume for this question there are 3 Option instances with id values of 2, 10, 34, so I want those to be the keys of the changeOptions Map
changeOptionsMapare IDs for other objects in the domain. Depending on that ID I want to use a differentChangeMap