Bit-TypedArray icon indicating copy to clipboard operation
Bit-TypedArray copied to clipboard

Bit-TypedArray does not support bitOffset, length in constructor

Open zipzapzanigan opened this issue 3 years ago • 1 comments

> import BitArray from "@bitarray/typedarray"
undefined
> let d = new BitArray([0,1,1], 0, 10)
<repl>.ts:5:31 - error TS2554: Expected 1 arguments, but got 3.

BitArray doesn't seem to support both buffer, byteOffset and length in the constructor, as other TypedArrays do:

new TypedArray(buffer, byteOffset, length)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#constructor

zipzapzanigan avatar Apr 23 '22 01:04 zipzapzanigan

Thanks for the comment.

I would suggest this requires careful thinking. For standards TypedArrays, it is always possible to match boundaries however one likes, with a proper combination of byteOffset and length. But, for bit arrays, it is not possible to match all bit boundaries.

Ideally, we should go for bitOffset rather than byteOffset (as suggested by you in the issue title). But this leads to other issues (this is not how array buffers work).

At this stage, I am not convinced byteOffset makes sense here, and has any practical use. I am rather inclined to allow calling the constructor with a buffer instance, but no other arguments (tbd). Are you with me?

swiing avatar Apr 24 '22 09:04 swiing