简体   繁体   English

打字稿编译错误: <x> 不可分配给类型 <y>

[英]Typescript compilation error: <x> is not assignable to type <y>

When I am trying to assign 当我尝试分配

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

where content is a json. 内容是json。

where Blob is declared in lib.d.ts as lib.d.ts中将Blob声明为

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

it is giving me the following error: 它给我以下错误:

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

I have verified the spelling of blobParts a number of times 我已经多次验证了blobParts的拼写

您应该使用new关键字构造Blob ...

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Typescript 错误:X 类型的参数不能分配给 Y 类型的参数 - Typescript error: Argument of Type X is not assignable to parameter of type Y 类型“X”不可分配给带有打字稿的“Y”类型 - Type"X' is not assignable to type "Y" with typescript Typescript泛型,类型&#39;X&#39;不能赋值为&#39;Y&#39; - Typescript generics, Type 'X' is not assignable to type 'Y' 打字稿 + useRef<X|Y> : X 型不能分配给 Y 型 - TypeScript + useRef<X|Y>: Type X is not assignable to type Y 打字稿:X 类型的参数不能分配给 Y 和 X 类型的参数。X 类型不能分配给 Y 类型 - Typescript: Argument of type X is not assignable to parameter of type Y & X. Type X is not assignable to type Y 在量角器打字稿上进行拖放操作时出错,类型““ {x:540,y:504}””的参数无法分配给类型“ ILocation”的参数 - Error on drag and drop action on protractor typescript, Argument of type '“{x: 540, y: 504}”' is not assignable to parameter of type 'ILocation' 如何解决打字稿中无法将X类型分配给Y类型错误的问题? - How can I fix this type X is not assignable to type Y error in typescript? 如何解决打字稿错误“&#39;X&#39;类型的参数不可分配给&#39;Y&#39;类型的参数 - How to resolve typescript error "Argument of type 'X' is not assignable to parameter of type 'Y' Typescript - “X”类型的参数不能分配给“Y”类型的参数 - Typescript - Argument of type “X” is not assignable to parameter of type “Y” TYPESCRIPT :类型“typeof X”的参数不能分配给类型为“Y”的带有扩展的参数 - TYPESCRIPT : Argument of type 'typeof X' is not assignable to parameter of type 'Y' with extends
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM