There are two different definitions of ReadableStream
in this code which are not compatible with each other.
Blob
comes from the DOM typings. Blob.stream()
returns a ReadableStream<any>
as defined in lib.dom.d.ts
:
interface ReadableStream<R = any> {
readonly locked: boolean;
cancel(reason?: any): Promise<void>;
getReader(): ReadableStreamDefaultReader<R>;
pipeThrough<T>(transform: ReadableWritablePair<T, R>, options?: StreamPipeOptions): ReadableStream<T>;
pipeTo(dest: WritableStream<R>, options?: StreamPipeOptions): Promise<void>;
tee(): [ReadableStream<R>, ReadableStream<R>];
}
GitHub source
Readable.wrap()
expects to be called with a ReadableStream
from the NodeJS definitions in @types/node/globals.ts
:
interface ReadableStream extends EventEmitter {
readable: boolean;
read(size?: number): string | Buffer;
setEncoding(encoding: BufferEncoding): this;
pause(): this;
resume(): this;
isPaused(): boolean;
pipe<T extends WritableStream>(destination: T, options?: { end?: boolean; }): T;
unpipe(destination?: WritableStream): this;
unshift(chunk: string | Uint8Array, encoding?: BufferEncoding): void;
wrap(oldStream: ReadableStream): this;
[Symbol.asyncIterator](): AsyncIterableIterator<string | Buffer>;
}
GitHub source
Your code attempts to assign a DOM ReadableStream
to a function that requires a NodeJS ReadableStream
. You get a error telling you all of the properties that are expected from this Node version which aren't present in the DOM version variable data.stream()
.
ReadableStream<Uint8Array>
into the node.js format? I have the same problem except the functionality works, its just the type that is complaining. – Nahshun