简体   繁体   English

&#39;ReadableStream 类型的参数<any> &#39; 不可分配给类型为 &#39;ReadableStream&#39; 的参数

[英]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>];
}

GitHub source GitHub 源码


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>;
}

GitHub source GitHub 源码


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.

相关问题 类型“ any []”的参数不能分配给类型“ A”的参数。 类型“ any []”中缺少属性“ a” - Argument of type 'any[]' is not assignable to parameter of type 'A'. Property 'a' is missing in type 'any[]' &#39;{ period: any; 类型的参数价格:任意; }&#39; 不可分配给类型为 &#39;MAInput&#39; 的参数 - Argument of type '{ period: any; prices: any; }' is not assignable to parameter of type 'MAInput' &#39;{ [key: string]: any; 类型的参数 }&#39; 不可分配给“any[]”类型的参数 - Argument of type '{ [key: string]: any; }' is not assignable to parameter of type 'any[]' 参数类型不能分配给类型的参数 - Argument type is not assignable to parameter of type x 类型的参数不能分配给 '{ x: any; 类型的参数。 }' - Argument of type x is not assignable to parameter of type '{ x: any; }' typescript:类型&#39;any []&#39;的参数不能分配给&#39;[]&#39;类型的参数.ts(2345) - typescript : Argument of type 'any[]' is not assignable to parameter of type '[]'.ts(2345) '{验证器类型的参数:任何; }' 不可分配给“ValidatorFn”类型的参数 - Argument of type '{ validator: any; }' is not assignable to parameter of type 'ValidatorFn React Typescript:'{ [x: number]: any; 类型的参数 }' 不可分配给类型的参数 - React Typescript: Argument of type '{ [x: number]: any; }' is not assignable to parameter of type “string”类型的参数不能分配给类型为“{[key:string]:any;}的参数 - Argument of type 'string' is not assignable to parameter of type '{ [key:string]:any;} “事件”类型的参数不可分配给“CdkDragMove”类型的参数<any> &#39; - Argument of type 'Event' is not assignable to parameter of type 'CdkDragMove<any>'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM