String Enums Have No Reverse Mapping
What You'll Learn
You'll discover a key difference between numeric and string enums: string enums are one-way mappings only.
The Core Difference
In numeric enums, TypeScript automatically creates reverse mappings — you can look up both the value from the name and the name from the value. String enums work differently: they're one-way only. You can access the value from the name, but not the name from the value.
Think of it like a one-way street versus a two-way street. Numeric enums let you travel in both directions, while string enums only go from name to value.
Why This Happens
enum NumericEnum {
Up = 0,
Down = 1
}
enum StringEnum {
Success = "SUCCESS",
Error = "ERROR"
}
console.log(NumericEnum.Up); // 0
console.log(NumericEnum[0]); // "Up" ← reverse mapping!
console.log(StringEnum.Success); // "SUCCESS"
console.log(StringEnum["SUCCESS"]); // Error! No reverse mapping
TypeScript doesn't generate reverse mappings for string enums because the string values themselves are already descriptive. With numeric enums, reverse mapping helps you convert numbers back to meaningful names. With string enums, you already have the meaningful value — there's no need to look up the enum member name.
Practical Impact
If you need to validate whether a string exists as an enum value, you'll need to check values explicitly rather than using bracket notation:
const isValidStatus = (value: string): boolean => {
return Object.values(StringEnum).includes(value);
};
Key Takeaway: String enums only map from member name to string value, never backwards — unlike numeric enums which create two-way mappings for convenient reverse lookups.