ESLint Rules for TypeScript Enums

2.1.0 · active · verified Sun Apr 19

eslint-plugin-typescript-enum provides ESLint rules specifically designed to manage and disallow the use of TypeScript enums within a project. The plugin operates on the premise that TypeScript enums, while a core language feature, introduce runtime representations that conflict with TypeScript's design goal of being a typed superset of JavaScript without adding runtime functionality. It highlights concerns such as potential type unsafety, caveats, and better modern alternatives like `const assertions`, `string unions`, and `discriminated unions`. The current stable version is 2.1.0, and the package appears to have an active release cadence, with several minor versions released recently. Its key differentiator is its explicit stance against TypeScript enums, aligning with a growing sentiment in the TypeScript community that discourages their use in favor of more JavaScript-native patterns. This makes it a critical tool for developers aiming to maintain a consistent, future-proof, and JavaScript-aligned codebase by enforcing alternatives.

Common errors

Warnings

Install

Imports

Quickstart

Configures ESLint to use the recommended rules of `eslint-plugin-typescript-enum`, effectively disallowing TypeScript enums in your project by applying the recommended rule set.

module.exports = {
  // Specifies the ESLint parser for TypeScript
  parser: "@typescript-eslint/parser",
  // Specifies the ESLint plugin to use
  plugins: ["typescript-enum"],
  // Extends with the recommended configuration from the plugin, disallowing enums
  extends: ["plugin:typescript-enum/recommended"],
  // Optional: Add other ESLint configurations as needed
  parserOptions: {
    ecmaVersion: 2020,
    sourceType: "module",
    // Required for rules that need type information
    project: './tsconfig.json'
  },
  rules: {
    // Additional custom rules or overrides if necessary
  }
};

view raw JSON →