useShorthandArrayType
诊断类别:lint/style/useShorthandArrayType
¥Diagnostic Category: lint/style/useShorthandArrayType
自从:v1.0.0
¥Since: v1.0.0
在表达数组类型时,此规则提倡使用 T[]
简写而不是 Array<T>
。
¥When expressing array types, this rule promotes the usage of T[]
shorthand instead of Array<T>
.
¥Examples
¥Invalid
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 │
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 │
¥Valid
¥Related links