Urara-Blog/node_modules/.pnpm-store/v3/files/83/028bcaa1f3685b80492f257b1757e945955d2d7167b1578233dd60456a78509b5db732b344372cd35d51884ee9573bd744bf0eeae112a4433f24667849947b
2022-08-14 01:14:53 +08:00

55 lines
1.2 KiB
Text

---
description: 'Disallow generic `Array` constructors.'
---
> 🛑 This file is source code, not the primary documentation location! 🛑
>
> See **https://typescript-eslint.io/rules/no-array-constructor** for documentation.
## Rule Details
This rule extends the base [`eslint/no-array-constructor`](https://eslint.org/docs/rules/no-array-constructor) rule.
It adds support for the generically typed `Array` constructor (`new Array<Foo>()`).
<!--tabs-->
### ❌ Incorrect
```ts
/*eslint no-array-constructor: "error"*/
Array(0, 1, 2);
new Array(0, 1, 2);
```
### ✅ Correct
```ts
/*eslint no-array-constructor: "error"*/
Array<number>(0, 1, 2);
new Array<Foo>(x, y, z);
Array(500);
new Array(someOtherArray.length);
```
## How to Use
```jsonc
{
// note you must disable the base rule as it can report incorrect errors
"no-array-constructor": "off",
"@typescript-eslint/no-array-constructor": ["error"]
}
```
## Options
See [`eslint/no-array-constructor` options](https://eslint.org/docs/rules/no-array-constructor#options).
<sup>
Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-array-constructor.md)
</sup>