https://twitter.com/CreatorQsF/status/1300135251516092416
http://var.blog.jp/archives/75246136.html
普通に JSON.stringify
を使って、 tuple
に限らず Object
を string
にしてkeyに設定する
Use JSON.stringify
so that key will be string
of not only tuple
but Object
const f = (key: any): string => {
return JSON.stringify(key);
};
const m = new Map();
const k1 = [1, "hello"];
const v1 = "hello world";
const k2 = [2, "world"];
const v2 = "tuple map";
const k3 = [1, "hello"];
m.set(f(k1), v1);
m.set(f(k2), v2);
if (m.get(f(k3)) === v1) console.log("ok");
else console.error("not same");
// output: ok