[英]Typescript error: Argument of Type X is not assignable to parameter of type Y
[英]Typescript compilation error: <x> is not assignable to type <y>
當我嘗試分配
let blob:Blob = {blobParts: [content]};
內容是json。
在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;
};
它給我以下錯誤:
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的拼寫
您應該使用new
關鍵字構造Blob ...
let blob: Blob = new Blob([content]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.