Skip to content

TS4242: Enum member must have initializer

Error message

                Enum member must have initializer.
              

Quick summary

An enum member needs a value but doesn't have one, and TypeScript can't infer it.

Why this happens

  • String enum member without an explicit value

  • Enum member after a computed member without a value

  • Mixed enum with some members having values and others not

Minimal example

✗ Broken code
enum Color {
  Red = 'RED',
  Green,    // TS4242: needs initializer
  Blue = 'BLUE',
}
✓ Fixed code
enum Color {
  Red = 'RED',
  Green = 'GREEN', // ✅
  Blue = 'BLUE',
}

Add an explicit string value to the Green member.

How to diagnose

  • Check the enum definition for members without values

  • Determine what value each member should have

How to fix

  • Add an initializer to the enum member

  • Make the enum a const enum if appropriate

  • Ensure all string enum members have explicit values

← Back to language