Skip to content

No Array Constructor Index Assignment

SuggestionAuto-fixableRoblox
small-rules/no-array-constructor-index-assignment

Disallow new Array<T>() followed by contiguous index assignments; use an array literal instead.

Diagnostic Messages

preferArrayLiteral
Use an array literal instead of new Array<T>() followed by index assignments.

Configuration

This rule does not accept options.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/no-array-constructor-index-assignment": "error"
}
}

Examples

array index assignment after construction
const samples = new Array<string>();
samples[0] = replacement;

After auto-fix

const samples = [replacement];
array literal initialization
const samples = [replacement];