-
Couldn't load subscription status.
- Fork 13.1k
Description
π Search Terms
Blob, BlobPart, TypedArray
π Version & Regression Information
- This changed between versions 5.8 and 5.9
β― Playground Link
π» 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.