無陣列建構函數
不允許通用
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 開啟Array<number>(0, 1, 2);
new Array<Foo>(x, y, z);
Array(500);
new Array(someOtherArray.length);
在 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"
}
};
在遊戲場中嘗試這項規則 ↗