Closed rbsdc closed 2 years ago
This is because byte[]
is not a Uint8Array
but it is a Array<number>
with extra metadata. We are considering mapping primitive arrays to TypedArray but that's not going to be soon.
If you really would like to use byte[]
in JS, one option you have is to create a static function that returns a byte[]
.
Either the function can take byte parameters and return constructed array:
static byte[] createByteArray(byte... bytes){ return bytes;}
or you can manipulate returned empty array to add items.
If you care about using Uint8Array
from Java side, then you can use Elemental2 or JsArrayLike
from the jsinterop.base library.
Thank you for the clarification. I already thought that Uint8Array
might not be the correct byte[]
equivalent, but wondered anyhow why it did work when using a plain byte[]
parameter (as described above and in the other issue). Anyway, by using your suggested method static byte[] createByteArray(byte... bytes){ return bytes;}
and manipulating the returned array I made it work. Thank you again!
Describe the bug When byte[] is used as type parameter and an Uint8Array is used as return value in JavaScript, then an error is thrown. If byte[] is used directly, it works fine with Uint8Array. Mentioned in a comment here: https://github.com/google/j2cl/issues/144.
To Reproduce The following code does work when transpiled to JavaScript:
In Javascript:
The following does not work:
In Javascript:
Bazel version 5.1.0