Microsoft/TypeScript
GitHub ã§èŠãIncorrect type returned by TextEncoder.encode
Open
#60,846 opened on 2024幎12æ23æ¥
BugDomain: lib.d.tsHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð 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
ð» 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.