Skip to content

Add byte stream bounds to WebTransport stream types - #2596

Merged
Jake Bailey (jakebailey) merged 2 commits into
microsoft:mainfrom
MartinFerret:fix-2439-webtransport-stream-types
Nov 30, 2026
Merged

Jake Bailey (jakebailey) merged 2 commits into
microsoft:mainfrom
MartinFerret:fix-2439-webtransport-stream-types

Conversation

@MartinFerret

Copy link
Copy Markdown
Contributor

Fixes #2439

WebTransportReceiveStream, WebTransportSendStream and WebTransportDatagramsWritable extended plain ReadableStream / WritableStream, so their chunks were any: reading gave you any, and you could write anything, even a string.

I gave them proper bounds:

  • WebTransportReceiveStream extends ReadableStream<Uint8Array<ArrayBuffer>>
  • WebTransportSendStream extends WritableStream<BufferSource>
  • WebTransportDatagramsWritable extends WritableStream<BufferSource>

This matches how byte streams are already typed in lib.dom (Response.body for reading, CompressionStream.writable for writing), and the WebTransport spec, which rejects any chunk that isn't a BufferSource, for send streams and for datagrams.

The change is a few lines in inputfiles/patches/webtransport.kdl, with regenerated baselines. I also added unittests/files/webtransport.ts: it checks the chunk types, that a string can't be written anymore, and that all three are still assignable to ReadableStream / WritableStream. It fails without the patch.

One thing I noticed: a few related properties in the same patch file still use plain streams (WebTransportBidirectionalStream.readable / .writable, the return type of createUnidirectionalStream(), and WebTransportDatagramDuplexStream.writable), so chunks there are still any. I can update them here or in a follow-up, whichever you prefer.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the PR!

This section of the codebase is owned by Kagami Sascha Rosylight (@saschanaz) - if they write a comment saying "LGTM" then it will be merged.

@saschanaz

Copy link
Copy Markdown
Contributor

Looks reasonable, thanks!

@MartinFerret

Copy link
Copy Markdown
Contributor Author

Thanks! You think I should fix the related properties in a follow-up PR?

@saschanaz

Copy link
Copy Markdown
Contributor

LGTM

@saschanaz

Copy link
Copy Markdown
Contributor

Thanks! You think I should fix the related properties in a follow-up PR?

SGTM

@github-actions

Copy link
Copy Markdown
Contributor

Sorry Kagami Sascha Rosylight (@saschanaz), this PR has merge conflicts. They'll need to be fixed before this can be merged.

@MartinFerret
Martin Ferret (MartinFerret) force-pushed the fix-2439-webtransport-stream-types branch from 3423f1f to 0996d5d Compare November 11, 2026 07:58
@MartinFerret

Copy link
Copy Markdown
Contributor Author

Rebased on main, the conflicts are now fixed. Could you take another look when you have a minute? Thanks!

@MartinFerret
Martin Ferret (MartinFerret) force-pushed the fix-2439-webtransport-stream-types branch from 0996d5d to 446af8d Compare November 12, 2026 14:43
@MartinFerret

Copy link
Copy Markdown
Contributor Author

Kagami Sascha Rosylight (@saschanaz) the conflicts are fixed and all checks pass. Could you LGTM it again so the bot can merge it? Thanks!

@MartinFerret

Martin Ferret (MartinFerret) commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Found a bug here while double-checking before 7.1, and pushed a fix.

Uint8Array<ArrayBuffer> was also emitted in the ts5.5/ts5.6 outputs, where Uint8Array isn't generic (TS2315). The extends type now goes through the same conversion as properties, so those outputs get a plain Uint8Array. It needed a small extends { type ... } node in the KDL, happy to reshape it if you prefer.

Checked with TS 5.5.4, 5.6.3 and 5.9.3: no errors, main output unchanged, npm test passes.

@jakebailey
Jake Bailey (jakebailey) merged commit f7effdf into microsoft:main Nov 30, 2026
6 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.

[Web API type definition issue] Missed bounds in WebTransportReceiveStream, WebTransportSendStream and WebTransportDatagramsWritable parent types

3 participants