I have a custom class called Foo
:
class Foo {
constructor(public v: any) {
}
}
And I have a map where Foo
is my Key:
const map = new Map<Foo, string>();
As far as I know, TypeScript does not support comparison overloading. How can I ensure that retrieving the key works correctly?
const foo = new Foo(1234);
map.get(foo);
Below is the full code snippet:
class Foo {
constructor(public v: any) {
}
}
const map = new Map<Foo, string>();
const foo = new Foo(1234);
map.set(foo, "HELLO WORLD");
const foo2 = new Foo(1234);
console.log(map.get(foo2)); // This will not work
console.log(map.get(foo)); // This will work correctly
You can view my issue here: Link to Issue