close

no-array-constructor

Configuration

PresetConfigured Value
✅ ts.configs.recommended"error"
rslint.config.ts
import { defineConfig, ts } from '@rslint/core';

export default defineConfig([
  ts.configs.recommended,
  {
    rules: {
      '@typescript-eslint/no-array-constructor': 'error',
    },
  },
]);

Rule Details

Disallow generic Array constructors.

Use of the Array constructor to create arrays is generally discouraged in favor of array literal notation because of the single-argument pitfall and because the Array global may be redefined.

The rule allows single-argument calls since they are commonly used to create arrays with a specific size.

Examples of incorrect code for this rule:

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

Examples of correct code for this rule:

[];
[x, y];
[0, 1, 2];
new Array(500); // single argument creates array with size
Array(someOtherArray.length);
new Array<Foo>(); // TypeScript generic syntax
new Array<Foo>(1, 2, 3);

Original Documentation