blu*_*per 5 javascript blob node.js
刚刚收到一个错误:
Argument of type 'Blob' is not assignable to parameter of type 'string | Blob'.
Type 'import("buffer").Blob' is not assignable to type 'Blob'.
The types returned by 'stream()' are incompatible between these types.
Type '{}' is missing the following properties from type 'ReadableStream<any>': locked, cancel, getReader, pipeThrough, and 2 more.
Run Code Online (Sandbox Code Playgroud)
并且无法理解发生了什么事。尝试重新启动 vscode 但没有帮助。Blob不可分配给 type 的 param Blob。?!那么Blob流返回的结果和平常不一样吗Blob?
这是我的代码
Argument of type 'Blob' is not assignable to parameter of type 'string | Blob'.
Type 'import("buffer").Blob' is not assignable to type 'Blob'.
The types returned by 'stream()' are incompatible between these types.
Type '{}' is missing the following properties from type 'ReadableStream<any>': locked, cancel, getReader, pipeThrough, and 2 more.
Run Code Online (Sandbox Code Playgroud)
当我尝试将文件附加到 formdata 时显示错误
Mat*_*ner 11
您正在使用两种不同的类型,称为Blob
您要导入的是来自节点的:
import { Blob } from 'buffer' // this is from node
Run Code Online (Sandbox Code Playgroud)
虽然您调用的 api ( FormData) 来自 DOM,并且需要BlobDOM 类型中定义的类型。这两种Blob类型并不相同
修复方法是删除importfor Blob。Blob这应该使用DOM 类型中定义的全局类型(前提是您已从项目中明确排除 DOM 类型)