1

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?

1

0

Browse other questions tagged or ask your own question.