{"record":{"id":"509462bab1e90b93","repo":"oxc-project/oxc","slug":"array-type-using-type-name-generic-name-is","errorCode":null,"errorMessage":"Array type using '{type_name}<{generic_name}>' is forbidden. Use '{readonly_prefix}{generic_name}[]' instead.","messagePattern":"Array type using '(.+?)<(.+?)>' is forbidden\\. Use '(.+?)(.+?)\\[\\]' instead\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"info","filePath":"crates/oxc_linter/src/rules/typescript/array_type.rs","lineNumber":187,"sourceCode":"    short_description = \"Require consistently using either `T[]` or `Array<T>` for arrays.\",\n);\n\nfn generic(readonly_prefix: &str, name: &str, type_name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"Array type using '{readonly_prefix}{type_name}[]' is forbidden. Use '{name}<{type_name}>' instead.\"\n    ))\n    .with_label(span)\n}\n\nfn generic_simple(readonly_prefix: &str, name: &str, type_name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"Array type using '{readonly_prefix}{type_name}[]' is forbidden for non-simple types. Use '{name}<{type_name}>' instead.\"\n    ))\n    .with_label(span)\n}\n\nfn array(readonly_prefix: &str, type_name: &str, generic_name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"Array type using '{type_name}<{generic_name}>' is forbidden. Use '{readonly_prefix}{generic_name}[]' instead.\"\n    ))\n    .with_label(span)\n}\n\nfn array_simple(\n    readonly_prefix: &str,\n    type_name: &str,\n    generic_name: &str,\n    span: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"Array type using '{type_name}<{generic_name}>' is forbidden for simple types. Use '{readonly_prefix}{generic_name}[]' instead.\"\n    ))\n    .with_label(span)\n}\n\nimpl Rule for ArrayType {","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/array_type.rs#L169-L205","documentation":"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.","triggerScenarios":"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.","commonSituations":"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>`.","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."],"exampleFix":"// before\nlet xs: Array<string> = [];\nfunction total(row: ReadonlyArray<number>) {}\n\n// after\nlet xs: string[] = [];\nfunction total(row: readonly number[]) {}","handlingStrategy":"fallback","validationCode":"null","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["typescript","oxlint","style","types","autofix","array-type"],"backgroundTag":"typescript-array-type-style","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}