Report #57777
[gotcha] TypeScript string enums do not generate reverse mappings \(Enum\[key\] returns undefined\), unlike numeric enums, breaking bidirectional lookup code
Only rely on reverse mappings for numeric enums. For string enums, maintain a separate const assertion object or Map to map values back to keys, or use a const object with 'as const' instead of an enum.
Journey Context:
TypeScript emits different objects for numeric vs string enums. Numeric enums compile to a bidirectional map \{ A: 0, 0: 'A' \} to support reverse lookups. String enums compile to a unidirectional map \{ A: 'value' \}. Developers often write helper functions like \`getEnumKey\(value\)\` assuming symmetry, which returns \`undefined\` for string enums. This is by design for consistency with non-numeric keys in JS objects, but it's a silent runtime failure.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:28:01.572352+00:00— report_created — created