oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.86k stars 2.74k forks source link

Bun.stdin.stream() TypeScript type is not iteratable #8765

Open jclem opened 8 months ago

jclem commented 8 months ago

What version of Bun is running?

1.0.26+c75e768a6

What platform is your computer?

Darwin 23.2.0 arm64 arm

What steps can reproduce the bug?

Write a program with the stdin example from the Bun documentation:

for await (const chunk of Bun.stdin.stream()) {
  // chunk is Uint8Array
  // this converts it to text (assumes ASCII encoding)
  const chunkText = Buffer.from(chunk).toString();
  console.log(`Chunk: ${chunkText}`);
}

What is the expected behavior?

No type errors should be reported.

What do you see instead?

A type error:

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

Additional information

Looks like ReadableStream isn't getting the async iterator from stream/web's definition (stream/web has it, lib/dom does not).

keverw commented 7 months ago

This is also happening with file.stream(). https://bun.sh/guides/read-file/stream - I'm guessing maybe they both are using the same types under the hood.

guest271314 commented 4 months ago

Another issue with Bun.stdin.stream() is the stream does not read stdin to completion, cf. Deno and Bun.