# @typescript-eslint/array-type

> Require either `T[]` or `Array<T>` for array types, consistently

`string[]` and `Array<string>` are the same type. A codebase that mixes the two makes readers stop and check whether the difference means something. This rule picks one. By default it's `T[]`, and `readonly T[]` for read-only arrays.

`--fix` rewrites the type to the other form.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/array-type" = "error" # or "warn"
```

Every option, set to its default. The ones that are commented out are unset by default.

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/array-type" = ["error", {
  default = "array", # "array", "generic" or "array-simple"
  # readonly = <"array", "generic" or "array-simple">,
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```ts
const names: Array<string> = [];
const ids: ReadonlyArray<number> = [1, 2];
```

Not reported:

{/* good */}
```ts
const names: string[] = [];
const ids: readonly number[] = [1, 2];
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `default` | `"array"` | The form for arrays you can change. |
| `readonly` | the value of `default` | The form for read-only arrays. |

Each takes one of these values:

| Value | What it does |
| --- | --- |
| `"array"` | Require `T[]` and `readonly T[]`. |
| `"generic"` | Require `Array<T>` and `ReadonlyArray<T>`. |
| `"array-simple"` | Require `T[]` when `T` is simple, and `Array<T>` when it isn't. |

A simple type is a keyword such as `string`, a name without type arguments such as `User`, or an array. Unions, functions, object types, and generics aren't simple.

{/* bad {"options": [{"default": "generic"}]} */}
```ts
const names: string[] = [];
```

With `"array-simple"`, both lines are reported:

{/* bad {"options": [{"default": "array-simple"}], "count": 2} */}
```ts
const names: Array<string> = [];
const values: (string | number)[] = [];
```

{/* good {"options": [{"default": "array-simple"}]} */}
```ts
const names: string[] = [];
const values: Array<string | number> = [];
```

`readonly` can differ from `default`:

{/* good {"options": [{"default": "array", "readonly": "generic"}]} */}
```ts
const names: string[] = [];
const ids: ReadonlyArray<number> = [1, 2];
```
