oxc-project/oxc · error · OxcDiagnostic
Explicit enum values must only be literal values (string…
Error message
Explicit enum values must only be literal values (string, number, boolean, etc.).
What it means
Raised by typescript/prefer-literal-enum-member when an enum member is initialized with a computed/non-literal value (a variable, function call, or template expression). Non-literal initializers prevent safe enum usage.
Solutions
- Initialize enum members with literal string, number, or boolean values.
- Move computed values out of the enum into constants.
- Enable allowBitwiseCombinations if bitwise flag enums are intended.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/typescript/prefer_literal_enum_member.rs:16 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/1a668bd25b9ecaca.
Report an issue: GitHub.
Appendix: source
Thrown at crates/oxc_linter/src/rules/typescript/prefer_literal_enum_member.rs:16
use oxc_ast::{AstKind, ast::Expression};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use oxc_syntax::operator::{BinaryOperator, UnaryOperator};
use schemars::JsonSchema;
use serde::Deserialize;
use crate::{
AstNode,
context::{ContextHost, LintContext},
rule::{DefaultRuleConfig, Rule},
};
fn prefer_literal_enum_member_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(
"Explicit enum values must only be literal values (string, number, boolean, etc.).",
)
.with_help("Require all enum members to be literal values.")
.with_label(span)
}
#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct PreferLiteralEnumMember {
/// When set to `true`, allows bitwise expressions in enum member initializers.
/// This includes bitwise NOT (`~`), AND (`&`), OR (`|`), XOR (`^`), and shift operators (`<<`, `>>`, `>>>`).
allow_bitwise_expressions: bool,
}
declare_oxc_lint!(
/// ### What it does
///
/// Explicit enum values must only be literal values (string, number, boolean, etc.).View on GitHub (pinned to e1e7af627c)