arrayTypes
Reports array type syntax that doesn't match the configured style.
✅ This rule is included in the tsstylisticandstylisticStrictpresets.
TypeScript provides two equivalent ways to define an array type: T[] and Array<T>.
Using the shorthand T[] syntax consistently is more concise and idiomatic.
This rule reports when Array<T> or ReadonlyArray<T> is used instead of the shorthand syntax.
Examples
Section titled “Examples”const const values: string[]
values: interface Array<T>
Array<string> = [];function function process(items: Array<number>): void
process(items: number[]
items: interface Array<T>
Array<number>): void {}type type StringArray = string[]
StringArray = interface Array<T>
Array<string>;const const values: readonly string[]
values: interface ReadonlyArray<T>
ReadonlyArray<string> = [];const const values: string[]
values: string[] = [];function function process(items: number[]): void
process(items: number[]
items: number[]): void {}type type StringArray = string[]
StringArray = string[];const const values: readonly string[]
values: readonly string[] = [];Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your codebase uses Array<T> consistently, or if you prefer the generic syntax for its explicit nature, you may disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
useConsistentArrayType - ESLint:
@typescript-eslint/array-type - Oxlint:
typescript/array-type
Made with ❤️🔥 around the world by
the Flint team and contributors.