You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constdata=newTextEncoder().encode("hello")// ^? Uint8Array<ArrayBufferLike>// The `ArrayBufferLike` may include `SharedArrayBuffer`, but `encode()` // only supports `ArrayBuffer`, so this breaks code expecting an `ArrayBuffer`.functionprocessData(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.
I think this is expected behavior change introduced in 5.7 series.
Consider change ArrayBuffer to ArrayBufferLike which is an union of both ArrayBuffer and SharedArrayBuffer.
This is definitely fallout from the TS5.7 change at #59417, but the question is whether it should be. Is TextEncoder.encode() known to produce a Uint8Array<ArrayBuffer>? I don't think it ever produces something else (there's encodeInto() that lets you bring your own buffer) but I'm no expert on these things. But if it is always producing a Uint8Array<ArrayBuffer> then it's probably best for the lib to reflect that. If it isn't, is that documented somewhere?
π Search Terms
TypedArray, Uint8Array, ArrayBufferLike, TextEncoder
π Version & Regression Information
β― Playground Link
Playground link
π» Code
π 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
The text was updated successfully, but these errors were encountered: