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

Namespace Pollution

Enums create both a type and a value in the same scope, which can cause naming conflicts and confusion about what you're referencing.

Namespace Pollution

You'll learn: How enums create both a compile-time type and a runtime value in the same namespace, which can lead to naming conflicts and confusion.

Unlike most TypeScript features that disappear during compilation, enums have a unique dual nature. When you declare an enum, TypeScript creates two things with the same name:

  1. A type you can use in type annotations
  2. A runtime object containing the enum values

The Problem

This "namespace pollution" means your enum name occupies space in both the type world and the value world simultaneously:

enum Status {
  Active = "active",
  Inactive = "inactive"
}

// Status as a TYPE
const userStatus: Status = Status.Active;

// Status as a VALUE (runtime object)
console.log(Status);
// { Active: "active", Inactive: "inactive" }

Where Conflicts Arise

This dual existence can cause confusion. If you try to import something else called Status, or declare a variable with that name, you get conflicts:

enum Status { /* ... */ }

// Error: Cannot redeclare 'Status'
const Status = { /* ... */ };

// Error: Cannot redeclare 'Status'
type Status = { /* ... */ };

You can't tell at a glance whether Status refers to the type or the runtime value without checking context. This is especially confusing when reading others' code or during refactoring.

This doesn't happen with type aliases or interfaces—those exist only at compile-time and vanish after compilation, keeping the value namespace clean.

Key Takeaway: Enums occupy both the type namespace and the value namespace simultaneously, which can cause naming collisions and make code harder to reason about since a single identifier refers to two different things.