Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jyang14 opened this issue Jun 11, 2021 · 2 comments
Closed

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

jyang14 opened this issue Jun 11, 2021 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@jyang14
Copy link

jyang14 commented Jun 11, 2021

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)))
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 14, 2021
@RyanCavanaugh
Copy link
Member

See #40466

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants