ProjectStack
typescript

TS2322: Enum type mismatch — string or number not assignable to enum type

You're passing a raw string or number where TypeScript expects a specific enum value. Enums create a distinct type — even if the string matches an enum member's value, TypeScript won't automatically accept it without an explicit enum member reference or assertion.

Common causes

  • Passing a string literal ('active') where an enum value (Status.Active) is expected
  • Numeric enums accept number assignments, but string enums require the exact enum member
  • Comparing or assigning between two different enum types
  • Getting an enum value from an external source (API, config) as a plain string

How to fix it

  1. Use the enum member directly: Status.Active instead of 'active'
  2. Cast with a type assertion if data comes from outside TypeScript: status as Status
  3. Import and use the enum value from wherever it's defined rather than repeating the string
  4. For API responses, validate and map to the enum: const status = data.status as Status

Example

enum Status { Active = 'active', Inactive = 'inactive' } const s: Status = 'active'; // error TS2322: Type '"active"' is not assignable to type 'Status'.

Assigning the string 'active' directly instead of using the Status.Active enum member

Browse more errors

The Developer Hub covers 150+ errors across Git, npm, Node.js, Python, TypeScript, and Docker — with plain-English explanations and fix steps.