fix(ext/web): narrow ReadableStreamBYOBRequest.view to Uint8Array#33477
Merged
Conversation
The WHATWG Streams spec change at whatwg/streams#1367 specifies that `ReadableStreamBYOBRequest.view` is always a `Uint8Array` (the BYOB controller already constructs it that way internally). Reflect that both in the public type declaration in `lib.deno_web.d.ts` and in the JSDoc on the implementation, narrowing the return type from `ArrayBufferView | null` to `Uint8Array<ArrayBuffer> | null`. Fixes denoland#33476.
bartlomieju
approved these changes
Apr 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Per the spec change at whatwg/streams#1367,
ReadableStreamBYOBRequest.viewis always aUint8Array— the BYOB controller already constructs it that way internally. Narrow the public type fromArrayBufferView | nulltoUint8Array<ArrayBuffer> | null:cli/tsc/dts/lib.deno_web.d.ts— the user-facing TypeScript declaration.ext/web/06_streams.js— JSDoc on both the internal[_view]slot and theviewgetter.Before this PR, code like
const v: Uint8Array = req.view!failed type-checking with TS2740 againstArrayBufferView<ArrayBufferLike>. After, it compiles and rejects assignment to incompatible views (e.g.DataView) with a meaningful TS2322.Fixes #33476.
Test plan
tests/unit/streams_test.ts(ReadableStreamBYOBRequest.view is a Uint8Array) that:const view: Uint8Array<ArrayBuffer> | null = byobReq.view;assignment that compile-fails without the fix and compiles with it,instanceof Uint8Arrayand that writes through it round-trip back to the BYOB reader../x buildclean;./x fmtclean;./x lintclean.