Course contentsShow
← TypeScript
Lesson 510 of 1,79612. EnumsFree lesson

String Enums Lack Reverse Mapping

String enums don't provide reverse lookups like numeric enums, creating inconsistent behavior between the two enum variants.

String Enums Lack Reverse Mapping

You'll learn why string enums behave differently than numeric enums when it comes to looking up values by their keys.

The Inconsistent Behavior

Remember how numeric enums provide reverse mapping—the ability to look up an enum member's name using its numeric value? String enums don't offer this feature. When you create a string enum, TypeScript only generates one-way mappings from name to value, creating an inconsistency between the two enum variants.

Why This Happens

With numeric enums, TypeScript generates runtime code that stores both directions:

// Numeric enum (has reverse mapping)
enum HttpStatus {
  OK = 200,
  NotFound = 404
}

// You can do both:
const code = HttpStatus.OK;        // 200
const name = HttpStatus[200];      // "OK"

But string enums only map name-to-value:

// String enum (NO reverse mapping)
enum LogLevel {
  Info = "INFO",
  Error = "ERROR"
}

const level = LogLevel.Info;       // "INFO" ✓
const name = LogLevel["INFO"];     // Error! ✗

The Practical Impact

This asymmetry can surprise developers who expect consistency between enum types. You cannot take a string enum's value and look up its key at runtime. If you need that capability, you must manually create a separate lookup object or use a different pattern entirely.

This limitation reinforces that string enums are simpler at runtime—they're essentially named string constants without the extra reverse-mapping machinery.

Key Takeaway: String enums only provide name-to-value mapping, unlike numeric enums which support bidirectional lookups, creating an important behavioral difference between the two enum types.