This Blob is not a pure Blob type, but a custom Blob type that has been extended with the name and lastModified properties.
In TypeScript's built-in type definitions, a Blob type object that has the lastModified and name properties is considered a File type. This is indicated in the lib.dom.d.ts file of TypeScript:
typescript/lib/lib.dom.d.ts
/** Provides information about files and allows JavaScript in a web page to access their content. */
interface File extends Blob {
readonly lastModified: number;
readonly name: string;
}
Therefore, since the Blob returned by this function has the lastModified and name properties, it can be safely converted to a File type without issues.
What I Did
I have updated the return types of the following three functions from Blob to File:
Why
According to
index.d.ts
, theimageCompression(compress)
function is expected to return a File object. https://github.com/Donaldcwl/browser-image-compression/blob/d933bc8e483a9853ed2b57338e035e8c45e40dc7/lib/index.d.ts#L32 However, it currently returns a Blob object rather than a File.This Blob is not a pure Blob type, but a custom Blob type that has been extended with the
name
andlastModified
properties.In TypeScript's built-in type definitions, a Blob type object that has the
lastModified
andname
properties is considered a File type. This is indicated in the lib.dom.d.ts file of TypeScript:Therefore, since the Blob returned by this function has the
lastModified
andname
properties, it can be safely converted to a File type without issues.What I Did
I have updated the return types of the following three functions from Blob to File:
imageCompression(compress)
getFilefromDataUrl
canvasToFile
before
after