Skip to main content

no-array-constructor

禁止通用 Array 构造函数.

ESLint 配置 中扩展"plugin:@typescript-eslint/recommended" 可启用此规则。

🔧

此规则报告的一些问题可通过 --fix ESLint 命令行选项自动修复

🧱

This is an "extension" rule that replaces a core ESLint rule to work with TypeScript. See Rules > Extension Rules.

This rule extends the base no-array-constructor rule from ESLint core. 它增加了对泛型 Array 构造函数 (new Array<Foo>()) 的支持。

¥It adds support for the generically typed Array constructor (new Array<Foo>()).

Array(0, 1, 2);
new Array(0, 1, 2);
Open in Playground

选项

See eslint/no-array-constructor's options.

如何使用

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"
}
});

在线运行试试这个规则 ↗

资源

Taken with ❤️ from ESLint core.