{"record":{"id":"be77da9188244f66","repo":"oxc-project/oxc","slug":"array-type-using-readonly-prefix-type-name","errorCode":null,"errorMessage":"Array type using '{readonly_prefix}{type_name}[]' is forbidden. Use '{name}<{type_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":173,"sourceCode":"    /// const readonlyArr: ReadonlyArray<number> = [1, 2, 3];\n    /// ```\n    ///\n    /// Examples of **correct** code for this rule (with default configuration):\n    /// ```typescript\n    /// const arr: number[] = new Array<number>();\n    /// const readonlyArr: readonly number[] = [1, 2, 3];\n    /// ```\n    ArrayType,\n    typescript,\n    style,\n    fix,\n    config = ArrayTypeConfig,\n    version = \"0.2.8\",\n    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}","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/typescript/array_type.rs#L155-L191","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Apply the autofix: `oxlint --fix` rewrites `T[]` to `Array<T>` (and `readonly T[]` to `ReadonlyArray<T>`).","Manually rewrite declarations: `let xs: Array<string> = [];`.","If both spellings should coexist (simple types as `T[]`, complex as `Array<T>`), switch the option to `array-simple`/`generic-simple` instead of `generic`."],"exampleFix":"// before\nlet xs: string[] = [];\ntype Rows = readonly number[];\n\n// after\nlet xs: Array<string> = [];\ntype Rows = ReadonlyArray<number>;","handlingStrategy":"fallback","validationCode":"null","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Adopt one array spelling repo-wide via the array-type rule and autofix (`oxlint --fix`) rather than hand-editing.","Record the chosen option ('generic') in .oxlintrc.json so editors and CI enforce the same style.","For codegen output, make the generator emit the configured style so lint never disagrees with generated files."],"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"}