no-array-constructor
Disallow generic
Array
constructors.
✅
Extending "plugin:@typescript-eslint/recommended"
in an ESLint configuration enables this rule.
🔧
Some problems reported by this rule are automatically fixable by the --fix
ESLint command line option.
This rule extends the base eslint/no-array-constructor
rule.
It adds support for the generically typed Array
constructor (new Array<Foo>()
).
- ❌ Incorrect
- ✅ Correct
Array(0, 1, 2);
new Array(0, 1, 2);
Open in PlaygroundArray<number>(0, 1, 2);
new Array<Foo>(x, y, z);
Array(500);
new Array(someOtherArray.length);
Open in PlaygroundOptions
See eslint/no-array-constructor
's options.
How to Use
- Flat Config
- Legacy Config
eslint.config.mjs
export default tseslint.config({
rules: {
// Note: you must disable the base rule as it can report incorrect errors
"no-array-constructor": "off",
"@typescript-eslint/no-array-constructor": "error"
}
});
.eslintrc.cjs
module.exports = {
"rules": {
// Note: you must disable the base rule as it can report incorrect errors
"no-array-constructor": "off",
"@typescript-eslint/no-array-constructor": "error"
}
};
Try this rule in the playground ↗