Skip to content

Make chunk param of WritableStreamDefaultWriter.write and TransformStreamDefaultController.enqueue non-optional - #2452

Merged
github-actions[bot] merged 3 commits into
microsoft:mainfrom
ikeyan:WritableStreamDefaultWriter-TransformStreamDefaultController-chunk-required
Mar 18, 2026
Merged

Make chunk param of WritableStreamDefaultWriter.write and TransformStreamDefaultController.enqueue non-optional#2452
github-actions[bot] merged 3 commits into
microsoft:mainfrom
ikeyan:WritableStreamDefaultWriter-TransformStreamDefaultController-chunk-required

Conversation

@ikeyan

@ikeyan ikeyan commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Follow up #2425
The issue was first mentioned in #1682

Test script

This script demonstrates that calling enqueue() without arguments is behaviorally identical to enqueue(undefined). This confirms that allowing the omission of arguments in these methods poses a risk to type safety, unless the stream's generic type is explicitly defined to include undefined or void.

I successfully ran the script on Node.js v24.13.1, Chrome 145.0.7632.160, Firefox 148.0.2, Safari 26.3.1

function assert(condition, message) {
  if (!condition) {
    throw new Error("Assertion failed: " + message);
  }
}

async function runTests() {
  // === TransformStream Test ===
  const ts = new TransformStream({
    start(controller) {
      controller.enqueue();          // No arguments
      controller.enqueue(undefined); // Explicit undefined
    }
  });

  const reader = ts.readable.getReader();
  const tsResult1 = await reader.read();
  const tsResult2 = await reader.read();

  assert(tsResult1.value === undefined, "enqueue() should result in undefined");
  assert(tsResult2.value === undefined, "enqueue(undefined) should result in undefined");

  // === WritableStream Test ===
  const writtenChunks = [];
  const ws = new WritableStream({
    write(chunk) {
      writtenChunks.push(chunk); // Store written chunks for verification
    }
  });

  const writer = ws.getWriter();
  await writer.write();          // No arguments
  await writer.write(undefined); // Explicit undefined
  await writer.close();

  assert(writtenChunks[0] === undefined, "write() should write undefined");
  assert(writtenChunks[1] === undefined, "write(undefined) should write undefined");
  assert(writtenChunks.length === 2, "exactly 2 elements are written");
}

// Execute tests. If success, no output.
await runTests();

@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.

@Bashamega Adam Naji (Bashamega) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not format the jsonc file, it creates extra diffs

Comment thread inputfiles/overridingTypes.jsonc Outdated
Comment thread inputfiles/overridingTypes.jsonc Outdated
Comment thread inputfiles/overridingTypes.jsonc Outdated
@saschanaz

Copy link
Copy Markdown
Contributor

Thanks all! LGTM

@github-actions
github-actions Bot merged commit 1a37a85 into microsoft:main Mar 18, 2026
9 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Merging because Kagami Sascha Rosylight (@saschanaz) is a code-owner of all the changes - thanks!

@ikeyan
ikeyan deleted the WritableStreamDefaultWriter-TransformStreamDefaultController-chunk-required branch March 18, 2026 13:27
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.

3 participants