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>
.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-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 │
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 │
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 │
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 │
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 │
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 │