Typescript编译错误:<x>不能分配给<y>类型

时间:2018-05-24 12:26:55

标签: typescript

当我尝试分配

let blob:Blob = {blobParts: [content]};

其中content是json。

其中Bloblib.d.ts中声明为

  interface Blob {
      readonly size: number;
      readonly type: string;
      msClose(): void;
      msDetachStream(): any;
      slice(start?: number, end?: number, contentType?: string): Blob;
  }

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

它给了我以下错误:

Type '{ blobParts: any[]; }' is not assignable to type 'Blob'. Object literal may only specify known properties, and 'blobParts' does not exist in type 'Blob'.

我已多次验证blobParts的拼写

1 个答案:

答案 0 :(得分:0)

您应该使用new关键字...

构建Blob
let blob: Blob = new Blob([content]);