[英]Argument of type 'ReadableStream<any>' is not assignable to parameter of type 'ReadableStream'
I want to get a Readable form a Blob.我想获得一个可读形式的 Blob。
import {Readable} from 'stream';
const data: Blob = new Blob( );
const myReadable: Readable = (new Readable()).wrap(data.stream());
myReadable.pipe(ext);
I get This error我收到此错误
ERROR in src/app/features/recorder/components/record-panel/record-panel.component.ts:80:38 - error TS2345: Argument of type 'ReadableStream<any>' is not assignable to parameter of type 'ReadableStream'.
Type 'ReadableStream<any>' is missing the following properties from type 'ReadableStream': readable, read, setEncoding, pause, and 22 more.
I use Node 14 angular 10 and typescript我使用 Node 14 angular 10 和 typescript
There are two different definitions of ReadableStream
in this code which are not compatible with each other.这段代码中有两个不同的
ReadableStream
定义,它们彼此不兼容。
Blob
comes from the DOM typings. Blob
来自 DOM 类型。 Blob.stream()
returns a ReadableStream<any>
as defined in lib.dom.d.ts
: Blob.stream()
返回在lib.dom.d.ts
定义的ReadableStream<any>
:
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>];
}
Readable.wrap()
expects to be called with a ReadableStream
from the NodeJS definitions in @types/node/globals.ts
: Readable.wrap()
期望使用来自@types/node/globals.ts
定义的ReadableStream
@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>;
}
Your code attempts to assign a DOM ReadableStream
to a function that requires a NodeJS ReadableStream
.您的代码尝试将 DOM
ReadableStream
分配给需要 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()
.您会收到一条错误消息,告诉您此 Node 版本预期的所有属性,这些属性不存在于 DOM 版本变量
data.stream()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.