src/content/docs/linter/rules/use-consistent-array-type.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="TypeScript and TSX" icon="seti:typescript"> ## Summary - Rule available since: `v1.5.0` - Diagnostic Category: [`lint/style/useConsistentArrayType`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`@typescript-eslint/array-type`](https://typescript-eslint.io/rules/array-type){
"linter": {
"rules": {
"style": {
"useConsistentArrayType": "error"
}
}
}
}
Require consistently using either T[] or Array<T>
TypeScript provides two equivalent ways to define an array type: T[] and Array<T>.
The two styles are functionally equivalent.
Using the same style consistently across your codebase makes it easier for developers to read and understand array types.
let invalid: Array<foo>;
let invalid: Promise<Array<string>>;
let invalid3: Array<Foo<Bar>>;
const valid: Array<string | number> = ['a', 'b'];
const valid: Array<{ prop: string }> = [{ prop: 'a' }];
const valid: Array<() => void> = [() => {}];
const valid: MyType[] = ['a', 'b'];
const valid: string[] = ['a', 'b'];
const valid: readonly string[] = ['a', 'b'];
Use the options to specify the syntax of array declarations to use.
{
"linter": {
"rules": {
"style": {
"useConsistentArrayType": {
"options": {
"syntax": "shorthand"
}
}
}
}
}
}
The syntax to use:
generic: array declarations will be converted to Array<T> or ReadonlyArray<T>shorthand: array declarations will be converted to T[] or readonly T[]Default: shorthand