fix: Change function to return File instead of Blob #203
+20
−21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
According to
index.d.ts
, theimageCompression(compress)
function is expected to return a File object.browser-image-compression/lib/index.d.ts
Line 32 in d933bc8
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