Lint Rules

useShorthandArrayType (since v0.7.0)

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

Examples

Invalid

let invalid: Array<foo>;
style/useShorthandArrayType.js:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━

   Use shorthand T[] syntax instead of Array<T> syntax.
  
  > 1 │ let invalid: Array<foo>;
                ^^^^^^^^^^
    2 │ 
  
   Suggested fix: Use shorthand T[] syntax to replace
  
    1  - let·invalid:·Array<foo>;
      1+ let·invalid:·foo[];
    2 2  
  
let invalid: Promise<Array<string>>;
style/useShorthandArrayType.js:1:22 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━

   Use shorthand T[] syntax instead of Array<T> syntax.
  
  > 1 │ let invalid: Promise<Array<string>>;
                        ^^^^^^^^^^^^^
    2 │ 
  
   Suggested 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>>;
style/useShorthandArrayType.js:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━

   Use shorthand T[] syntax instead of Array<T> syntax.
  
  > 1 │ let invalid: Array<Foo<Bar>>;
                ^^^^^^^^^^^^^^^
    2 │ 
  
   Suggested 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]>;
style/useShorthandArrayType.js:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━

   Use shorthand T[] syntax instead of Array<T> syntax.
  
  > 1 │ let invalid: Array<[number, number]>;
                ^^^^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   Suggested 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]>;
style/useShorthandArrayType.js:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━

   Use shorthand T[] syntax instead of Array<T> syntax.
  
  > 1 │ let invalid: Array<[number, number]>;
                ^^^^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Use shorthand T[] syntax to replace
  
    1  - let·invalid:·Array<[number,·number]>;
      1+ let·invalid:·[number,·number][];
    2 2  
  
let invalid: ReadonlyArray<string>;
style/useShorthandArrayType.js:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━

   Use shorthand readonly T[] syntax instead of ReadonlyArray<T> syntax.
  
  > 1 │ let invalid: ReadonlyArray<string>;
                ^^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
   Suggested fix: Use shorthand readonly T[] syntax to replace
  
    1  - let·invalid:·ReadonlyArray<string>;
      1+ let·invalid:·readonly·string[];
    2 2  
  

Valid

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