Skip to content

no-literal-collection-key ​

map.get([x, y]), set.has({ id }): a lookup with an object created right there.

Why: Map and Set compare object keys by identity, not by contents (v8.dev). A new array or object is never the same object as the stored key, so the lookup always misses.

ts
const visited = new Set<number[]>();

export function seen(x: number, y: number): boolean {
  return visited.has([x, y]);
}

✅ Accepted: a primitive key

✓ Accepted0 diagnostics
ts
const visited = new Set<string>();

export function seen(x: number, y: number): boolean {
  return visited.has(`${x},${y}`);
}

For structured keys, KeyedMap from @evobug_com/safe-ts-std/dict maps them through a key function.

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra