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

Heterogeneous Enums (Mixed Types)

Mix numeric and string values in a single enum, though this pattern is rarely recommended.

Heterogeneous Enums (Mixed Types)

You'll learn how TypeScript allows mixing numeric and string values in a single enum—and why this is almost never a good idea.

What Are Heterogeneous Enums?

Unlike purely numeric or purely string enums, a heterogeneous enum contains both numeric and string values. TypeScript permits this pattern, but it's generally considered an anti-pattern because it combines the downsides of both enum types without clear benefits.

Syntax Example

enum Status {
  Active = 1,
  Inactive = "INACTIVE",
  Pending = 2,
  Error = "ERROR"
}

Here, Active and Pending are numeric, while Inactive and Error are strings. This is valid TypeScript, but it creates confusion:

const current: Status = Status.Active;  // 1
const failed: Status = Status.Error;    // "ERROR"

Why This Pattern Is Problematic

No reverse mapping for strings: Remember that only numeric enums support reverse mapping. In a heterogeneous enum, you lose this feature for the string members, creating inconsistent behavior.

Unclear intent: Mixing types signals unclear design. Are these really the same kind of thing? Should they be separate enums or even literal union types instead?

Runtime confusion: Code checking enum values must handle both numbers and strings, complicating logic.

When You Might See This

Occasionally in legacy code or when migrating from numeric to string enums incrementally—but even then, it's better to create a new enum and migrate cleanly.

Key Takeaway: TypeScript allows heterogeneous enums mixing numeric and string values, but this pattern sacrifices consistency and clarity—stick with purely numeric or purely string enums instead.