oxc-project/oxc · error · OxcDiagnostic

The value of the member {member_name:?} should be explicitly

Error message

The value of the member {member_name:?} should be explicitly defined.

What it means

Raised by typescript/prefer_enum_initializers when a TS enum member has no explicit initializer (e.g. `enum E { A, B }`). At the throw site the member silently receives an auto-incremented number (previous member + 1, or 0 for the first), so inserting or reordering members later shifts all following values — a hazard for serialized/persisted enums. prefer_enum_initializers_diagnostic fires from run() for each member lacking an initializer, naming the member in the message.

Source

Thrown at crates/oxc_linter/src/rules/typescript/prefer_enum_initializers.rs:14

use oxc_ast::{AstKind, ast::TSEnumMemberName};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{
    AstNode,
    context::{ContextHost, LintContext},
    fixer::RuleFixer,
    rule::Rule,
};

fn prefer_enum_initializers_diagnostic(member_name: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "The value of the member {member_name:?} should be explicitly defined."
    ))
    .with_help(format!(
        "Using default numerical values for enum members can cause bugs later on if the enum is modified. Instead give {member_name:?} an explicit initializer (for example `= 0` or `= '{member_name}'`)."
    ))
    .with_note(
        "TypeScript computes uninitialized enum members as numbers: the first one defaults \
         to `0`, and each following uninitialized member is the previous numeric value plus `1`.",
    )
    .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct PreferEnumInitializers;

declare_oxc_lint!(
    /// ### What it does
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Add an explicit initializer to every enum member (e.g. A = 0, B = 1 or string values).
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/typescript/prefer_enum_initializers.rs:14 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/2c6d1ec8e2f3cd1b. Report an issue: GitHub.