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. Use '{readonly_prefix}{generic_name}[]' instead. What it means
Diagnostic from the typescript `array-type` rule with the `array` option (check_and_report_error_array): every `Array<T>` / `ReadonlyArray<T>` reference is forbidden and must be written `T[]` / `readonly T[]`. This is the ESLint default option, so it fires out of the box on generic-style arrays.
Source
Thrown at crates/oxc_linter/src/rules/typescript/array_type.rs:187
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 {
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 {View on GitHub (pinned to e1e7af627c)
Solutions
- Apply the autofix: `oxlint --fix` rewrites `Array<T>` to `T[]` and `ReadonlyArray<T>` to `readonly T[]`.
- Rewrite manually: `let xs: string[]`, `function f(x: readonly number[])`.
- If you prefer generic style globally, set the option to `generic`; for a hybrid, use `array-simple` (brackets for simple elements, `Array<T>` for complex).
- Bare `Array` becomes `any[]` per the fix — replace it with a real element type while you are there.
Example fix
// before
let xs: Array<string> = [];
function total(row: ReadonlyArray<number>) {}
// after
let xs: string[] = [];
function total(row: readonly number[]) {} Defensive patterns
Strategy: fallback
Validate before calling
null
Prevention
- Since 'array' is the default, decide deliberately whether to keep it or switch to 'generic' — do not leave the choice implicit.
- Configure generators (OpenAPI/protobuf) to emit `T[]` so CI does not fight generated `Array<T>`.
- Run `oxlint --fix` in a dedicated style commit, not mixed with behavior changes.
When it happens
Trigger: Config `{ "array-type": ["error", "array"] }` or default; a TSTypeReference named `Array`/`ReadonlyArray` — `let xs: Array<string>`, `function f(x: ReadonlyArray<number>)` — triggers 'Array type using Array<string> is forbidden. Use string[] instead.' Also fires for bare `Array` with no type arguments (reported as `any`). Autofix included.
Common situations: The most common case overall since `array` is the default: any codebase using `Array<T>` style (common in Java/C#-flavored TS or auto-generated types) lights up; migrating generators or protobuf/OpenAPI output that emit `Array<T>`.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- Array type using '{readonly_prefix}{type_name}[]' is forbidd
- Array type using '{readonly_prefix}{type_name}[]' is forbidd
- Array type using '{type_name}<{generic_name}>' is forbidden
- Type can be trivially inferred from the initializer
- Avoid calls to the `Array` constructor
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/509462bab1e90b93.
Report an issue: GitHub.