scala-js/scala-js-dom

Confusing type of ImageData.data

Closed this issue · 3 comments

The ImageData.data is defined and documented as follows:

/** Is a Uint8ClampedArray representing a one-dimensional array containing the data in the RGBA order, with integer
* values between 0 and 255 (included).
*/
def data: js.Array[Int] = js.native

I am confused: is the type Uint8ClampedArray, or js.Array[Int]? Or are those types interchangeable somehow? If they are, perhaps the documentation could clarify how.

Hmm. I don't think those are interchangeable. Seems like a bug to me.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray

I guess the interface of both JS types is similar enough, they both contain length and bracket access, therefore one can perform some basic operations on TypedArray thinking it is a normal array.