Skip to content

array-type

JavaScript / TypeScriptstyleno fixdefault: off

Reports Array<T>, ReadonlyArray<T> and Readonly<T[]> written as generic types, each level of a nested one (Array<Array<number>> is two reports). The bare Array is not reported.

Two spellings of one type make code harder to scan and search; the bracket form T[] is shorter and reads left to right.

To fix, write T[] and readonly T[].

Reported
...
interface F { a: 1 }
...
type M = A | B;
let g: Array<number>, h: ReadonlyArray<string>, i: Readonly<string[]>, j: Array<number, string>, k: number[];
js:
lint:
rules:
array-type: warn # off (default), warn, error

Suppress one line with sudsy-disable-next-line array-type in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
typescript-eslint array-type partial only the default array style (default and readonly options); a local type named Array is still reported