scala-js / scala-js-dom

Statically typed DOM API for Scala.js
Other
315 stars 160 forks source link

Confusing type of ImageData.data #807

Closed OndrejSpanel closed 9 months ago

OndrejSpanel commented 10 months ago

The ImageData.data is defined and documented as follows:

https://github.com/scala-js/scala-js-dom/blob/7d0508cac24b4f2657c3525797fe633feb4849bc/dom/src/main/scala/org/scalajs/dom/ImageData.scala#L23-L26

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.

armanbilge commented 10 months ago

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

armanbilge commented 10 months ago

Yes, we should use this instead.

https://github.com/scala-js/scala-js/blob/7b3092ae64194af7ac34ad6c12f101a382956fdb/library/src/main/scala/scala/scalajs/js/typedarray/Uint8ClampedArray.scala#L24

OndrejSpanel commented 10 months ago

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.