Skip to main content

ts/preferShorthandArrayType

MISSING DOCUMENTATION

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

Examples

Invalid

let valid: Array<foo>;
let invalid: bar[];

 file.ts:1:11 lint/ts/preferShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━

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

  > 1let valid: Array<foo>;
                ^^^^^^^^^^
    2let invalid: bar[];

  Safe fix

  - Array<foo>
  + foo[]


let invalid: Array<foo, Array<string>>;

 file.ts:1:13 lint/ts/preferShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━

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

    let invalid: Array<foo, Array<string>>;
                 ^^^^^^^^^^^^^^^^^^^^^^^^^

  Safe fix

  - Array<foo,·Array<string>>
  + foo[]·|·(string[])[]

 file.ts:1:24 lint/ts/preferShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━

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

    let invalid: Array<foo, Array<string>>;
                            ^^^^^^^^^^^^^

  Safe fix

  - Array<string>
  + string[]


let invalid: Promise<Array<string>>;

 file.ts:1:21 lint/ts/preferShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━

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

    let invalid: Promise<Array<string>>;
                         ^^^^^^^^^^^^^

  Safe fix

  - Array<string>
  + string[]


let invalid: Array<Foo<Bar>>;

 file.ts:1:13 lint/ts/preferShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━

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

    let invalid: Array<Foo<Bar>>;
                 ^^^^^^^^^^^^^^^

  Safe fix

  - Array<Foo<Bar>>
  + Foo<Bar>[]

Valid

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