oxc-project/oxc · info · OxcDiagnostic

Array type using '{readonly_prefix}{type_name}[]' is forbidd

Error message

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

What it means

Diagnostic from the typescript `array-type` rule with the `generic-simple` option: bracket array syntax is forbidden only for non-simple element types. `string[]` stays legal, but object/union/function element types must use `Array<...>` because brackets around complex types read poorly.

Source

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

    /// ```
    ArrayType,
    typescript,
    style,
    fix,
    config = ArrayTypeConfig,
    version = "0.2.8",
    short_description = "Require consistently using either `T[]` or `Array<T>` for arrays.",
);

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

fn generic_simple(readonly_prefix: &str, name: &str, type_name: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "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 {

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Run `oxlint --fix` to convert only the non-simple offenders to `Array<...>`.
  2. Rewrite manually: `let users: Array<User>` for object/union elements, keep `number[]` for primitives.
  3. Re-check the option if you intended the stricter blanket `generic` rule instead of the simple-type carve-out.

Example fix

// before
type Points = { x: number; y: number }[];
let mixed: (string | number)[] = [];

// after
type Points = Array<{ x: number; y: number }>;
let mixed: Array<string | number> = [];
Defensive patterns

Strategy: fallback

Validate before calling

null

Prevention

When it happens

Trigger: Config `{ "array-type": ["error", "generic-simple"] }`; check_and_report_error_generic skips simple types (primitives, literals) but reports `TSArrayType` whose element is non-simple — `type Ps = { name: string }[]`, `let xs: (string | number)[]`, `readonly User[]` — telling you to use `Array<{ name: string }>` etc. Autofix included.

Common situations: Adopting the ESLint-compatible hybrid convention; enabling after a merge of codebases with mixed styles; hits cluster in React prop types (`props: Props[]`) and API DTO layers full of object types.

Understand the failure class

Related errors


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