Donaldcwl / browser-image-compression

Image compression in web browser
MIT License
1.3k stars 160 forks source link

Update TypeScript types #83

Closed jamiehaywood closed 3 years ago

jamiehaywood commented 4 years ago

Based on the Mozilla documentation - the File interface inherits from the Blob interface and therefore the union type is unnecessary.

The primary reason for raising this PR is I was receiving type errors in my code:

Type 'File | Blob' is not assignable to type 'File'.
  Type 'Blob' is missing the following properties from type 'File': lastModified, name
This change addresses this issue.
Donaldcwl commented 3 years ago

Thanks for your update!

xegulon commented 2 years ago

Why do I get a Blob object instead of a File one?

Donaldcwl commented 2 years ago

Why do I get a Blob object instead of a File one?

Since some browsers do not support the File constructor such as IE, this library uses Blob instead. To mimic the File object, the "name" and "lastModified" properties are added to the Blob object.