Skip to content

fix(ext/web): narrow ReadableStreamBYOBRequest.view to Uint8Array#33477

Merged
bartlomieju merged 1 commit into
denoland:mainfrom
fibibot:fix/byob-view-uint8array
Apr 25, 2026
Merged

fix(ext/web): narrow ReadableStreamBYOBRequest.view to Uint8Array#33477
bartlomieju merged 1 commit into
denoland:mainfrom
fibibot:fix/byob-view-uint8array

Conversation

@fibibot

@fibibot fibibot commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Per the spec change at whatwg/streams#1367, ReadableStreamBYOBRequest.view is always a Uint8Array — the BYOB controller already constructs it that way internally. Narrow the public type from ArrayBufferView | null to Uint8Array<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 the view getter.

Before this PR, code like const v: Uint8Array = req.view! failed type-checking with TS2740 against ArrayBufferView<ArrayBufferLike>. After, it compiles and rejects assignment to incompatible views (e.g. DataView) with a meaningful TS2322.

Fixes #33476.

Test plan

  • Added a unit test in tests/unit/streams_test.ts (ReadableStreamBYOBRequest.view is a Uint8Array) that:
    • includes a const view: Uint8Array<ArrayBuffer> | null = byobReq.view; assignment that compile-fails without the fix and compiles with it,
    • verifies at runtime that the value is an instanceof Uint8Array and that writes through it round-trip back to the BYOB reader.
  • ./x build clean; ./x fmt clean; ./x lint clean.

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
bartlomieju merged commit 783f42a into denoland:main Apr 25, 2026
220 of 222 checks passed
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

Successfully merging this pull request may close these issues.

Streams: narrow ReadableStreamBYOBRequest.view to Uint8Array

2 participants