Skip to content

useShorthandArrayType

Diagnostic Category: lint/style/useShorthandArrayType

Since: v1.0.0

When expressing array types, this rule promotes the usage of T[] shorthand instead of Array<T>.

let invalid: Array<foo>;
code-block.ts:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Use shorthand T[] syntax instead of Array<T> syntax.

> 1 │ let invalid: Array<foo>;
^^^^^^^^^^
2 │

Unsafe fix: Use shorthand T[] syntax to replace

1 - let·invalid:·Array<foo>;
1+ let·invalid:·foo[];
2 2

let invalid: Promise<Array<string>>;
code-block.ts:1:22 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Use shorthand T[] syntax instead of Array<T> syntax.

> 1 │ let invalid: Promise<Array<string>>;
^^^^^^^^^^^^^
2 │

Unsafe fix: Use shorthand T[] syntax to replace

1 - let·invalid:·Promise<Array<string>>;
1+ let·invalid:·Promise<string[]>;
2 2

let invalid: Array<Foo<Bar>>;
code-block.ts:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Use shorthand T[] syntax instead of Array<T> syntax.

> 1 │ let invalid: Array<Foo<Bar>>;
^^^^^^^^^^^^^^^
2 │

Unsafe fix: Use shorthand T[] syntax to replace

1 - let·invalid:·Array<Foo<Bar>>;
1+ let·invalid:·Foo<Bar>[];
2 2

let invalid: Array<[number, number]>;
code-block.ts:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Use shorthand T[] syntax instead of Array<T> syntax.

> 1 │ let invalid: Array<[number, number]>;
^^^^^^^^^^^^^^^^^^^^^^^
2 │

Unsafe fix: Use shorthand T[] syntax to replace

1 - let·invalid:·Array<[number,·number]>;
1+ let·invalid:·[number,·number][];
2 2

let invalid: Array<[number, number]>;
code-block.ts:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Use shorthand T[] syntax instead of Array<T> syntax.

> 1 │ let invalid: Array<[number, number]>;
^^^^^^^^^^^^^^^^^^^^^^^
2 │

Unsafe fix: Use shorthand T[] syntax to replace

1 - let·invalid:·Array<[number,·number]>;
1+ let·invalid:·[number,·number][];
2 2

let invalid: ReadonlyArray<string>;
code-block.ts:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Use shorthand readonly T[] syntax instead of ReadonlyArray<T> syntax.

> 1 │ let invalid: ReadonlyArray<string>;
^^^^^^^^^^^^^^^^^^^^^
2 │

Unsafe fix: Use shorthand readonly T[] syntax to replace

1 - let·invalid:·ReadonlyArray<string>;
1+ let·invalid:·readonly·string[];
2 2

let valid: Array<Foo | Bar>;
let valid: Array<keyof Bar>;
let valid: Array<foo | bar>;