Skip to content

array-type-generic

Pick one array type style and stick with it. This rule bans the bracket syntax (T[], readonly T[]) and rewrites it to the generic form (Array<T>, ReadonlyArray<T>).

The fixer handles four cases:

  1. T[] becomes Array<T>
  2. readonly T[] becomes ReadonlyArray<T>
  3. Nested brackets like string[][] become Array<Array<string>>
  4. Tuple arrays like [A, B][] become Array<[A, B]>

Standalone tuples are left alone.

eslint.config.ts
{
"cease-nonsense/array-type-generic": "error"
}
Incorrect
type Names = string[];
type Values = readonly number[];
type Pairs = [number, string][];
type Grid = string[][];
Correct
type Names = Array<string>;
type Values = ReadonlyArray<number>;
type Pairs = Array<[number, string]>;
type Grid = Array<Array<string>>;
type Point = [x: number, y: number];

Consistency

One array format across the codebase means less noise in code review.

Readability at depth

Array<Array<string>> is easier to parse than string[][], and ReadonlyArray<T> is clearer than readonly T[].

Safe autofix

The fixer walks the full type chain and preserves tuple semantics.