← All tips

TypeScript: `Map` for non-string keys

typescriptbasics

Use Map when keys aren’t naturally strings.

const m = new Map<object, number>();
const k = {};
m.set(k, 1);
console.log(m.get(k));