如何根据lib.d.ts定义创建一个Blob

时间:2014-09-05 02:03:10

标签: typescript

当我尝试创建Blob时,typescript编译器会出错

var content = '<a id="a"><b id="b">hey!</b></a>'; // the body of the new file...
var blob = new Blob([content], { type: "text/xml"});

Using tsc v1.0.1
error TS7005: Variable 'blob' implicitly has an 'any' type.
error TS2081: Supplied parameters do not match any signature of call target.
error TS2085: Could not select overload for 'new' expression.

我将lib.d.ts中的定义视为

declare var Blob: {
    prototype: Blob;
    new (blobParts?: any[], options?: BlobPropertyBag): Blob;
}

interface BlobPropertyBag {
    type?: string;
    endings?: string;
}

如何根据此定义使用new运算符? 如果它是一个bug,最好的方法是什么。

编辑:

它不会在typescript playground http://goo.gl/iWCT8B上出错。但是,我想我正在使用最新版本。

感谢。

1 个答案:

答案 0 :(得分:0)

那应该是有用的。对于我来说tsc 1.0.1没有错误:

enter image description here