สำหรับผู้ใช้ typescript คำตอบของผู้อื่น (โดยเฉพาะอย่างยิ่งczerny ) นั้นสามารถทำให้เป็นประเภทพื้นฐานที่ปลอดภัยและสามารถนำกลับมาใช้ใหม่ได้:
/**
 * Map that stringifies the key objects in order to leverage
 * the javascript native Map and preserve key uniqueness.
 */
abstract class StringifyingMap<K, V> {
    private map = new Map<string, V>();
    private keyMap = new Map<string, K>();
    has(key: K): boolean {
        let keyString = this.stringifyKey(key);
        return this.map.has(keyString);
    }
    get(key: K): V {
        let keyString = this.stringifyKey(key);
        return this.map.get(keyString);
    }
    set(key: K, value: V): StringifyingMap<K, V> {
        let keyString = this.stringifyKey(key);
        this.map.set(keyString, value);
        this.keyMap.set(keyString, key);
        return this;
    }
    /**
     * Puts new key/value if key is absent.
     * @param key key
     * @param defaultValue default value factory
     */
    putIfAbsent(key: K, defaultValue: () => V): boolean {
        if (!this.has(key)) {
            let value = defaultValue();
            this.set(key, value);
            return true;
        }
        return false;
    }
    keys(): IterableIterator<K> {
        return this.keyMap.values();
    }
    keyList(): K[] {
        return [...this.keys()];
    }
    delete(key: K): boolean {
        let keyString = this.stringifyKey(key);
        let flag = this.map.delete(keyString);
        this.keyMap.delete(keyString);
        return flag;
    }
    clear(): void {
        this.map.clear();
        this.keyMap.clear();
    }
    size(): number {
        return this.map.size;
    }
    /**
     * Turns the `key` object to a primitive `string` for the underlying `Map`
     * @param key key to be stringified
     */
    protected abstract stringifyKey(key: K): string;
}
ตัวอย่างการใช้งานนั้นง่ายนี้เพียงแค่แทนที่stringifyKeyวิธีการ ในกรณีของฉันฉัน stringify uriทรัพย์สินบางอย่าง
class MyMap extends StringifyingMap<MyKey, MyValue> {
    protected stringifyKey(key: MyKey): string {
        return key.uri.toString();
    }
}
ตัวอย่างการใช้งานนั้นเหมือนกับว่านี่เป็นเรื่องปกติ Map<K, V>ตัวอย่างการใช้งานแล้วเช่นถ้านี้เป็นประจำ
const key1 = new MyKey(1);
const value1 = new MyValue(1);
const value2 = new MyValue(2);
const myMap = new MyMap();
myMap.set(key1, value1);
myMap.set(key1, value2); // native Map would put another key/value pair
myMap.size(); // returns 1, not 2
               
              
===ดำเนินการทำงานหนักเกินไป วัตถุชุด ES6 ไม่มีวิธีการเปรียบเทียบใด ๆ.has()วิธีการและ.add()วิธีการทำงานเท่านั้นปิดมันเป็นวัตถุที่เกิดขึ้นจริงเดียวกันหรือค่าเดียวกันสำหรับดั้งเดิม