microsoft / microsoft/TypeScript

`controller.byobRequest` type incorrectly says value is possibly null while `autoAllocateChunkSize` is present.

Open
#62,224 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

### 🔎 Search Terms

autoAllocateChunkSize

### 🕗 Version & Regression Information

- This is the behaviour in every version I tried, and I reviewed the FAQ for entries about readable, streams, byob, and autoallocatechunksize

### ⏯ Playground Link

https://www.typescriptlang.org/play/?ts=6.0.0-dev.20250806#code/HYUw7gBASiCGAmsBGAbEBlALgJzgWwAoBvAKAgkwE8AHEALggCIlLMQBnRgGjIlgFdMAewCCKFEIDGsNgGEAFv2ABrdAEsAXvQgBGAAwAmACw9y1fuIKShwHEPEhsASgily5a7ez202AHSSEuwgBE4A3LweNnYO-ixCSDAAjvwcmH647NQ28AR64bwAvjyFBUA

### 💻 Code

```ts
new ReadableStream({
type: "bytes",
autoAllocateChunkSize: 1024,
pull(controller) {
controller.close();
controller.byobRequest.respond(0);
},
});
```

### 🙁 Actual behavior

TypeScript says `controller.byobRequest` can be `ReadableStreamBYOBRequest | null` and errors when one tries to do `.respond` on it as `null` doesn't have that.

### 🙂 Expected behavior

TypeScript should say `controller.byobRequest` is `ReadableStreamBYOBRequest` because the `autoAllocateChunkSize` property is set. Meaning it can't be null according to https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream#autoallocatechunksize

### Additional information about the issue

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided TypeScript Playground link and inspect the ReadableStream constructor typing around `autoAllocateChunkSize` and `controller.byobRequest`. Reproduce the nullability error, then determine how the typing should reflect the configured byte stream and verify that the example accepts `.respond(0)` without a null error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.