Skip to content

Stream example in bun.sh docs has Typescript error #11903

@thesmart

Description

@thesmart

What version of Bun is running?

1.1.13+bd6a60512

What platform is your computer?

Darwin 23.3.0 arm64 arm

What steps can reproduce the bug?

Take the stream example from the documentation:

const stream = new ReadableStream({
  start(controller) {
    controller.enqueue("hello");
    controller.enqueue("world");
    controller.close();
  },
});

for await (const chunk of stream) {
  console.info(chunk);
}

The code runs fine, but the stream symbol raises a typescript error in VSCode:

Type 'ReadableStream<any>' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.ts(2504)

Here is my package.json, right out of bun init;

{
  "name": "foobar",
  "module": "index.ts",
  "type": "module",
  "devDependencies": {
    "@types/bun": "^1.1.4"
  },
  "peerDependencies": {
    "typescript": "^5.0.0"
  }
}

What is the expected behavior?

Type ReadableStream should support async iteration.

What do you see instead?

Type 'ReadableStream<any>' must have a '[Symbol.asyncIterator]()' method that returns an async iterator.ts(2504)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocsImprovements or additions to documentationtypescriptSomething for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions