no-array-constructor
UnreleasedConfiguration
rslint.config.ts
Rule Details
Use of the Array constructor to construct a new array is generally discouraged in favor of array literal notation because of the single-argument pitfall and because the Array global may be redefined. The exception is when the Array constructor is used to intentionally create sparse arrays of a specified size by giving the constructor a single numeric argument.
This rule disallows Array constructors.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
This rule additionally supports TypeScript type syntax.
Examples of correct code for this rule:
Examples of incorrect code for this rule:
Differences from ESLint
- When the array constructor call is fixed onto a new line right after certain TypeScript-only constructs — a type alias (
type T = Foo), an ambient or overload function declaration (declare function foo()), an import-equals declaration (import Foo = Bar), or anas/satisfiestype cast — rslint's autofix inserts a leading;that ESLint omits (e.g.type T = Foo\n;[0, 1]instead oftype T = Foo\n[0, 1]). The extra semicolon never changes the resulting code's behavior. - In TypeScript files, rslint treats
Arrayas a predefined library variable even whenparserOptions.libis explicitly empty. For example, withparserOptions.lib: []andglobals: { Array: "off" }, rslint still reports and fixesArray(), while typescript-eslint does not. Native rule contexts do not currently expose parser-specific library selection.