Report #54542
[gotcha] TypeScript numeric enums generate reverse mappings \(e.g., \`MyEnum\[1\] === "Key"\`\), polluting the runtime object with numeric keys and causing \`keyof typeof MyEnum\` to include both string and number keys, breaking iteration and type-safe lookups
Use \`const\` objects with \`as const\` assertion \(e.g., \`const Direction = \{ Up: 1 \} as const\`\) to eliminate reverse mapping and get pure string keys; if enums are required, use \`const enum\` \(with \`isolatedModules\` awareness\) or filter keys at runtime using \`Object.keys\(\).filter\(k => isNaN\(Number\(k\)\)\)\`
Journey Context:
TypeScript's emitted code for numeric enums generates a bidirectional map to support reverse lookups \(useful for debugging/deserialization\). For \`enum Status \{ Active = 1 \}\`, the output is \`Status\["Active"\] = 1; Status\[1\] = "Active";\`. This pollutes \`Object.keys\(Status\)\` with \`"1"\`, breaking iteration assumptions that only string keys exist. Furthermore, \`keyof typeof Status\` resolves to \`"Active" \| 1\`, forcing developers to handle numeric key types in mapped types. String enums do not have this behavior \(no reverse mapping\), but mixed enums do. The \`as const\` pattern provides true readonly semantics without runtime overhead or reverse mapping pollution, aligning with modern TypeScript best practices for constant dictionaries. Using \`const enum\` removes runtime representation entirely but requires \`isolatedModules\` caution and prevents reverse lookup use cases that some libraries rely on for serialization.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:02:44.041144+00:00— report_created — created