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
- Run `oxlint --fix` to convert only simple-element `Array<T>` to `T[]`.
- Rewrite manually: `let xs: string[]` while keeping `let rows: Array<Row>`.
- 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
- Document the hybrid rule for the team: simple types get `T[]`, complex types get `Array<T>`.
- Let the autofix do the conversion; manual rewrites miss edge cases like `ReadonlyArray<'a'|'b'>`.
- Re-run the linter after autofix to catch nested cases (e.g. `Array<Array<string>>`) that need a second pass.
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
- 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/c25cb45d1a8ba9b7.
Report an issue: GitHub.