Introduction
I am currently work in project that I need to save the score of each user.
For this I used a Map<User, number>
to represent it.
Problematic
If I create map with a user named john:
let myMap: Map<User, number> = new Map();
myMap.set(new User("John","Hasherman"), 0);
And if I want to set John Hasherman’s score to 1 (voluntarily using a new instance and not the one previously used), with this code:
myMap.set(new User("John","Hasherman"), 1);
But TypeScript create a new element inside myMap.
Question
So my question is, do you know if it’s possible to customize the comparator used inside the map? like Java when defining hashCode()
and equals(o Object)
?