JS.TS.NO.ARRAY.CONSTRUCTOR

Disallow generic 'Array' constructors

Rule Details

This rule extends the base eslint/no-array-constructor (https://eslint.org/docs/rules/no-array-constructor) rule. It adds support for the generically typed Array constructor (new Array<Foo>()).

<!--tabs-->

Incorrect

Copy
/*eslint no-array-constructor: "error"*/

Array(0, 1, 2);
new Array(0, 1, 2);

Correct

Copy
/*eslint no-array-constructor: "error"*/

Array<number>(0, 1, 2);
new Array<Foo>(x, y, z);

Array(500);
new Array(someOtherArray.length);

How to Use

Copy
{
  // note you must disable the base rule as it can report incorrect errors
  "no-array-constructor": "off",
  "@typescript-eslint/no-array-constructor": ["error"]
}

Options

See eslint/no-array-constructor options (https://eslint.org/docs/rules/no-array-constructor#options).

The content on this page is adapted from the ESLint User Guide. Copyright © OpenJS Foundation and other contributors, www.openjsf.org. All rights reserved. https://eslint.org/docs/rules/