Skip to content

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

@imirkin

Description

@imirkin

πŸ”Ž Search Terms

Blob, BlobPart, TypedArray

πŸ•— Version & Regression Information

  • This changed between versions 5.8 and 5.9

⏯ Playground Link

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions