It seems like because of historic javascript reasons, Typescript is lax about the enforcement of ArrayBuffers. Because Uint8Array implements ArrayBufferView (i.e. it has a .buffer call that gives you an ArrayBuffer), it does not complain when you pass a Uin8Array to something that expects an ArrayBuffer. This is apparently because many JS interfaces declare they take an ArrayBuffer, but actually accept both, using the following gem of code:
const arrayBuffer = input instanceof Uint8Array ? input.buffer : input;
This under-documented quirk is unfortunate.
I would propose we update our FfiConverterArrayBuffer to explicitly take either an ArrayBuffer | ArrayBufferView and do the above operation. We can update the places where ArrayBuffer is passed in to also use the union type, or rely on the lax interpreter.
It seems like because of historic javascript reasons, Typescript is lax about the enforcement of ArrayBuffers. Because
Uint8Array
implementsArrayBufferView
(i.e. it has a.buffer
call that gives you an ArrayBuffer), it does not complain when you pass a Uin8Array to something that expects an ArrayBuffer. This is apparently because many JS interfaces declare they take an ArrayBuffer, but actually accept both, using the following gem of code:const arrayBuffer = input instanceof Uint8Array ? input.buffer : input;
This under-documented quirk is unfortunate.
I would propose we update our
FfiConverterArrayBuffer
to explicitly take either anArrayBuffer | ArrayBufferView
and do the above operation. We can update the places where ArrayBuffer is passed in to also use the union type, or rely on the lax interpreter.