eslint-plugin

@masknet/array/prefer-from

Disallow new Array(...) and prefer TypedArray.from(...) for iterable input

Rule Details

:x: Incorrect

new Array(3)
new Uint8Array([1, 2, 3])

new Array(...) is reported without an autofix because new Array(length) creates a sparse array, which is not equivalent to the dense array produced by common alternatives.

:white_check_mark: Correct

Uint8Array.from([1, 2, 3])

Attributes