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. Use '{name}<{type_name}>' instead.

What it means

Diagnostic from the typescript `array-type` rule with the `generic` option (or default-config path resolving to Generic in check_and_report_error_generic): every `T[]` / `readonly T[]` syntax is forbidden and must be written `Array<T>` / `ReadonlyArray<T>`. It enforces one consistent array spelling across the codebase.

Source

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

    /// const readonlyArr: ReadonlyArray<number> = [1, 2, 3];
    /// ```
    ///
    /// Examples of **correct** code for this rule (with default configuration):
    /// ```typescript
    /// const arr: number[] = new Array<number>();
    /// const readonlyArr: readonly number[] = [1, 2, 3];
    /// ```
    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)
}

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Apply the autofix: `oxlint --fix` rewrites `T[]` to `Array<T>` (and `readonly T[]` to `ReadonlyArray<T>`).
  2. Manually rewrite declarations: `let xs: Array<string> = [];`.
  3. If both spellings should coexist (simple types as `T[]`, complex as `Array<T>`), switch the option to `array-simple`/`generic-simple` instead of `generic`.

Example fix

// before
let xs: string[] = [];
type Rows = readonly number[];

// after
let xs: Array<string> = [];
type Rows = ReadonlyArray<number>;
Defensive patterns

Strategy: fallback

Validate before calling

null

Prevention

When it happens

Trigger: Config `{ "array-type": ["error", "generic"] }` (or object form `{ "default": "generic" }`); any TSArrayType node — `let xs: string[]`, `readonly number[]`, `type Rows = Row[]` — triggers 'Array type using ... is forbidden. Use Array<...> instead.' An autofix rewrites it.

Common situations: Teams standardizing on `Array<T>` (common in codebases that also alias array types); enabling the option and autofixing a legacy repo with `oxlint --fix`; mixed-style files after merging teams with different conventions.

Understand the failure class

Related errors


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