跳至主要內容

無陣列建構函數

不允許通用 Array 建構函式。

擴充 「plugin:@typescript-eslint/推薦" ESLint 組態 啟用這項規則。

🔧

這項規則回報的一些問題可由 --fix ESLint 命令列選項自動修復.

這項規則延伸基本 eslint/no-array-constructor 規則。它加入支援一般型別的 Array 建構函式 (new Array<Foo>())。

Array(0, 1, 2);
new Array(0, 1, 2);
在 Playground 開啟

選項

請參閱 eslint/no-array-constructor 選項

使用方法

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

在遊戲場中嘗試這項規則 ↗

資源

取自 ESLint 核心,❤️ 呈現。