#62324Blob constructor no longer accepts a TypedArray input (ts5.9)

imirkinimirkin
opened 2 months ago
Author

🔎 Search Terms

Blob, BlobPart, TypedArray

🕗 Version & Regression Information

  • This changed between versions 5.8 and 5.9

https://www.typescriptlang.org/play/?ts=5.9.2#code/DYUwLgBAhgTjBcECqBLAdmAHAQTlAnhALwRogDuy6WuMBAFANoC6AlANwBQokARsAHtexUhQgAhQbyawYbdkA

💻 Code

let arr: Uint8Array = new Uint8Array([]); let blob = new Blob([arr]);

🙁 Actual behavior

Type 'Uint8Array<ArrayBufferLike>' is not assignable to type 'BlobPart'. Type 'Uint8Array<ArrayBufferLike>' is not assignable to type 'ArrayBufferView<ArrayBuffer>'. Types of property 'buffer' are incompatible. Type 'ArrayBufferLike' is not assignable to type 'ArrayBuffer'. Type 'SharedArrayBuffer' is not assignable to type 'ArrayBuffer'. Types of property '[Symbol.toStringTag]' are incompatible. Type '"SharedArrayBuffer"' is not assignable to type '"ArrayBuffer"'.

🙂 Expected behavior

Successful compliation.

Additional information about the issue

This error is covered in https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-9.html#libdts-changes and in #62240.

However I think this is different -- there the advice is to add .buffer to type TypedArray. But I'd argue that the bug is in the Blob constructor specification. https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob says that the constructor should take "An iterable object such as an Array, having ArrayBuffers, TypedArrays, DataViews, Blobs, strings"

While this is precipitated by the changes to ArrayBuffer specification, it seems like the BlobPart should have been changed to compensate.