oxc-project/oxc · info · OxcDiagnostic

Array type using '{type_name}<{generic_name}>' is forbidden

Error message

Array type using '{type_name}<{generic_name}>' is forbidden for simple types. Use '{readonly_prefix}{generic_name}[]' instead.

What it means

Diagnostic from the typescript `array-type` rule with the `array-simple` option: `Array<T>` is forbidden only when the element type is simple (primitives, literal types). Complex elements keep `Array<...>`; simple ones must use bracket syntax, matching the common hybrid style guide.

Source

Thrown at crates/oxc_linter/src/rules/typescript/array_type.rs:199

        "Array type using '{readonly_prefix}{type_name}[]' is forbidden for non-simple types. Use '{name}<{type_name}>' instead."
    ))
    .with_label(span)
}

fn array(readonly_prefix: &str, type_name: &str, generic_name: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "Array type using '{type_name}<{generic_name}>' is forbidden. Use '{readonly_prefix}{generic_name}[]' instead."
    ))
    .with_label(span)
}

fn array_simple(
    readonly_prefix: &str,
    type_name: &str,
    generic_name: &str,
    span: Span,
) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "Array type using '{type_name}<{generic_name}>' is forbidden for simple types. Use '{readonly_prefix}{generic_name}[]' instead."
    ))
    .with_label(span)
}

impl Rule for ArrayType {
    fn from_configuration(value: serde_json::Value) -> Result<Self, serde_json::error::Error> {
        DefaultRuleConfig::<Self>::from_value(value).map(DefaultRuleConfig::into_inner)
    }

    fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
        match node.kind() {
            AstKind::TSArrayType(ts_array_type) => {
                check_array_type(
                    node,
                    ts_array_type.span,
                    &ts_array_type.element_type,
                    self.default_config(),

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Run `oxlint --fix` to convert only simple-element `Array<T>` to `T[]`.
  2. Rewrite manually: `let xs: string[]` while keeping `let rows: Array<Row>`.
  3. Confirm the option matches intent: if everything should be `T[]`, use plain `array`; if everything generic, use `generic`.

Example fix

// before
let xs: Array<string> = [];
type Flags = ReadonlyArray<'on' | 'off'>;

// after
let xs: string[] = [];
type Flags = readonly ('on' | 'off')[];
Defensive patterns

Strategy: fallback

Validate before calling

null

Prevention

When it happens

Trigger: Config `{ "array-type": ["error", "array-simple"] }`; in check_and_report_error_array, `Array<string>`, `Array<number>`, `ReadonlyArray<'a' | 'b'>` are flagged ('forbidden for simple types. Use ...[] instead.'), while `Array<{ id: number }>` is left alone. Autofix included.

Common situations: Teams that want `number[]` but also want `Array<{ complex }>` for readability; enabling the option across a repo where DTO code uses `Array<string>` from a generator; inconsistency reported after partial autofix runs.

Understand the failure class

Related errors


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