Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Change function to return File instead of Blob #203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KantaHasegawa
Copy link

@KantaHasegawa KantaHasegawa commented Jul 12, 2023

Why

According to index.d.ts, the imageCompression(compress) function is expected to return a File object.

declare function imageCompression(image: File, options: Options): Promise<File>;

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 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:

imageCompression(compress)
getFilefromDataUrl
canvasToFile

before

before

after

after

@KantaHasegawa
Copy link
Author

cc.
@Donaldcwl

rdhwan added a commit to MAXIMA-2023/mxm23-app-internal that referenced this pull request Jul 22, 2023
Ada bug (mungkin) di browser-image-compression yg seharusnya return File
malah return Blob, ada issue yang nge fix tp blom di pr di repo nya
See Donaldcwl/browser-image-compression#203
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant