Skip to content

Severity: error
Category: type-check
Stage: Stage 1

Description

TypeScript enum declarations are not valid SJS syntax. Enums generate runtime objects with non-obvious semantics (reverse mappings, numeric/string duality) and are not part of ECMAScript.

Use sum types with unit variants for discriminated constant sets.

Example

// ✗ error
enum Direction {    // SJS-E010
  Up,
  Down,
  Left,
  Right,
}

Fix

// ✓ correct — sum type with unit variants
type Direction = Up | Down | Left | Right

function move(d: Direction): string {
  return match d {
    Up    => "up",
    Down  => "down",
    Left  => "left",
    Right => "right",
  }
}

Or use a string union for simple string constants:

type Direction = "up" | "down" | "left" | "right"
  • SJS-E007 — non-exhaustive match
Documentation