TS 5.7+ ArrayBuffer drift: cast where ArrayBufferLike leaked

TypeScript 5.7 split ArrayBuffer / SharedArrayBuffer at the type level
(ArrayBuffer now exposes resizable/transfer/detached etc; SharedArrayBuffer
doesn't), and parametrized the typed-array constructors so plain
Uint8Array became Uint8Array<ArrayBufferLike>.

The renderer never uses SharedArrayBuffer, so this is type-level only —
narrowing back to ArrayBuffer at the boundaries:

- BinaryReader.readBytes() / .toArrayBuffer() return the underlying
  DataView buffer; cast to ArrayBuffer.
- BinaryWriter.getBuffer() same shape.
- WsSessionCrypto.randomNonce() now returns Uint8Array<ArrayBuffer>
  (it's always backed by a plain ArrayBuffer); aesGcmEncrypt/Decrypt
  nonce parameter retyped accordingly so SubtleCrypto.encrypt accepts
  it as BufferSource.
- ArrayBufferToBase64 now accepts Uint8Array | ArrayBufferLike directly
  (pako/inflate hands back Uint8Array<ArrayBuffer> which the old
  ArrayBuffer-only signature rejected).
This commit is contained in:
simoleo89
2026-05-11 21:09:22 +02:00
parent afb5f33ec2
commit c37171a61c
4 changed files with 8 additions and 8 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
export const ArrayBufferToBase64 = (buffer: ArrayBuffer) =>
export const ArrayBufferToBase64 = (buffer: ArrayBufferLike | Uint8Array) =>
{
let binary = '';
const bytes = new Uint8Array(buffer);
const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
const len = bytes.byteLength;
for(let i = 0; i < len; i++) (binary += String.fromCharCode(bytes[i]));