'Typescript Generic Map type not able to set KVP [duplicate]
I am trying to create a generic Map in typescript but no KVPs are getting set in the map.
class type1 {
public prop1: string;
}
var t1: type1 = {
prop1: '1'
};
var t2: type1 = {
prop1: '2'
};
let map = new Map<string, type1>();
map.set('1', t1);
map.set('2', t2);
console.log(JSON.stringify(map));
console.log(JSON.stringify(map['1']));
console.log(JSON.stringify(map['2']));
Console Output:
- "{}"
- undefined
- undefined
What am I doing wrong here?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|