Skip to content
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

Incorrect type returned by TextEncoder.encode #60846

Open
aryzing opened this issue Dec 23, 2024 · 0 comments
Open

Incorrect type returned by TextEncoder.encode #60846

aryzing opened this issue Dec 23, 2024 · 0 comments

Comments

@aryzing
Copy link

aryzing commented Dec 23, 2024

πŸ”Ž Search Terms

TypedArray, Uint8Array, ArrayBufferLike, TextEncoder

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about TextEncoder

⏯ Playground Link

Playground link

πŸ’» Code

const data = new TextEncoder().encode("hello")
//    ^? Uint8Array<ArrayBufferLike>
// The `ArrayBufferLike` may include `SharedArrayBuffer`, but `encode()` 
// only supports `ArrayBuffer`, so this breaks code expecting an `ArrayBuffer`.

function processData(d: ArrayBuffer) {
  // do stuff
}

processData(data.buffer) // This should work, but reported as type error

πŸ™ Actual behavior

Values returned by TextEncoder.encode are not assignable to ArrayBuffer.

πŸ™‚ Expected behavior

Values returned by TextEncoder.encode should be assignable to ArrayBuffer.

Additional information about the issue

https://stackoverflow.com/a/79300250/1494725

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant