Skip to content

Unable to pass an awaited ArrayBuffer to a TypedArray constructorΒ #44557

Closed
@jyang14

Description

@jyang14

Bug Report

πŸ”Ž Search Terms

TypedArray, ArrayBuffer, Promise.then, await

πŸ•— Version & Regression Information

  • This changed between versions v3.3.3333 and v3.5.1

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

const array = new Uint8Array(await Promise.resolve().then(() => new ArrayBuffer(10)))

πŸ™ Actual behavior

The above code throws the following error when passing to a TypedArray an awaited ArrayBuffer from a Promise involving a then call

No overload matches this call.
  The last overload gave the following error.
    Argument of type 'Iterable<number> | ArrayBuffer' is not assignable to parameter of type 'ArrayBuffer'.
      Type 'Iterable<number>' is missing the following properties from type 'ArrayBuffer': byteLength, slice, [Symbol.toStringTag]

πŸ™‚ Expected behavior

The code should work because the following will not throw an error as the follow examples don't throw an error (also in playground link):

// refactoring the arrayBuffer definition to a separate variable doesn't throw an error
const arrayBuffer = await Promise.resolve().then(() => new ArrayBuffer(10))
const array = new Uint8Array(arrayBuffer)
// without the "then" it doesn't throw an error
const array = new Uint8Array(Promise.resolve(new ArrayBuffer(10)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions