Report #75852
[gotcha] Map distinguishes numeric keys 1 and string keys '1', while Object treats them as the same property
When migrating from Objects to Maps, audit all key types; cast keys to strings explicitly if Object-like behavior is desired, or use Map.get\(1\) vs Map.get\('1'\) consistently
Journey Context:
Objects coerce property names to strings via ToString\(\), so \`obj\[1\]\` and \`obj\['1'\]\` access the same property. Maps use SameValueZero equality \(similar to Object.is\), which distinguishes \`-0\` from \`\+0\` \(though Map treats them as same via SameValueZero\), and importantly, does NOT coerce types. Thus \`map.set\(1, 'number'\)\` and \`map.set\('1', 'string'\)\` create two entries. Developers refactoring Objects to Maps for safer key types often assume the key behavior is similar, leading to 'missing' values when they \`map.get\(stringId\)\` but stored with numeric ID from a database. The fix requires explicit key normalization \(e.g., \`String\(id\)\`\) or strict typing in TypeScript to catch mismatches.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:54:42.953558+00:00— report_created — created