TypeScript 中的 Blob

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13124080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:45:48  来源:igfitidea点击:

Blob in TypeScript

typescript

提问by Jo David

I am trying to write a file downloader in TypeScript using the FileSystem API.

我正在尝试使用 FileSystem API 在 TypeScript 中编写文件下载器。

When I'm trying to create a new Blob object:

当我尝试创建一个新的 Blob 对象时:

var blob: Blob = new Blob(xhr.response, JSON.stringify(mime));

I'm getting the error:

我收到错误:

Supplied parameters do not match any signature of call target

It's possible to create a Blob without any parameters:

可以创建一个没有任何参数的 Blob:

var blob: Blob = new Blob();

But that doesn't help.

但这无济于事。

The (deprecated) fall back for Blob is the BlobBuilder object but TypeScript (VS 2012 Plugin) only offers the MSBlobBuilderobject.

Blob 的(已弃用)回退是 BlobBuilder 对象,但 TypeScript(VS 2012 插件)仅提供该MSBlobBuilder对象。

What am I doing wrong? Or does TypeScript not know about the Blob constructor?

我究竟做错了什么?或者 TypeScript 不知道 Blob 构造函数?

采纳答案by Fenton

The definition for Blobin the lib.d.ts library only includes an empty constructor:

Bloblib.d.ts 库中的定义只包含一个空的构造函数:

declare var Blob: {
    prototype: Blob;
    new (): Blob;
}

If this is incorrect, you could submit back the corrected version, or override it in your code. Here is a rough guess at what the original declaration should look like.

如果这是不正确的,您可以提交回更正的版本,或在您的代码中覆盖它。这是对原始声明应该是什么样子的粗略猜测。

declare var Blob: {
    prototype: Blob;
    new (): Blob;
    new (request: any, mime: string): Blob;
}

I haven't specified the type for the first parameter and the names may be wrong - but as you know what Blobis up to, you can adjust these as required.

我没有指定第一个参数的类型,名称可能是错误的 - 但正如你所知Blob,你可以根据需要调整这些。