Report #16913
[gotcha] TypeScript string enums do not have reverse mapping unlike numeric enums
Use const assertions \(as const\) objects for string enums to enable reverse mapping via Object.keys or a Map; avoid TS enums for string values if reverse lookup needed
Journey Context:
TypeScript numeric enums generate bidirectional mapping: 'Enum.A' returns 0 and 'Enum\[0\]' returns 'A'. However, string enums only generate forward mapping \(Enum.A = 'value'\) with no reverse lookup because string keys are not valid property names in the generated object without additional runtime cost. Developers assume symmetry and try 'MyEnum\[value\]' getting undefined. Common mistake is using string enums for database status codes then needing to map back to keys. Alternatives: 'as const' objects provide type safety without runtime overhead, or using a Map/Record for bidirectional mapping. If using TS enums strictly, numeric ones are the only ones supporting reverse mapping.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T03:56:02.096588+00:00— report_created — created