node icon indicating copy to clipboard operation
node copied to clipboard

Incompatible ReadableStream TypeScript types

Open davidkarolyi opened this issue 1 year ago • 0 comments

Version

v20.12.1

Platform

Darwin arm64

Subsystem

No response

What steps will reproduce the bug?

  1. Install the @types/node type definition package
  2. Create a response object and store it's body as a stream, and try to provide it as the input of the Readable.fromWeb method.
import { Readable } from 'stream';
const stream = new Response('hello').body!;
Readable.fromWeb(stream);
  1. You will get an error message saying that the type are incompatible.
Argument of type 'ReadableStream<Uint8Array>' is not assignable to parameter of type 'ReadableStream<any>'.
  Type 'ReadableStream<Uint8Array>' is missing the following properties from type 'ReadableStream<any>': values, [Symbol.asyncIterator]

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

The fromWeb function should use the same type definition as the global ReadableStream.

What do you see instead?

An type error:

Argument of type 'ReadableStream<Uint8Array>' is not assignable to parameter of type 'ReadableStream<any>'.
  Type 'ReadableStream<Uint8Array>' is missing the following properties from type 'ReadableStream<any>': values, [Symbol.asyncIterator]

Additional information

The issue coming from the fact that the globalThis.ReadableStream<Uint8Array> and the ReadableStream definiton in node:stream/web is incompatible.

davidkarolyi avatar May 23 '24 15:05 davidkarolyi