b64-to-blob icon indicating copy to clipboard operation
b64-to-blob copied to clipboard

Import with Typescript

Open maxime1992 opened this issue 6 years ago • 0 comments

Hi,

thanks for the library :)

I'm trying to use it within an Angular app (and Typescript).

If I import it like that: import b64toBlob from 'b64-to-blob';

and then use it like that:

const contentType = 'image/png';
const blob = b64toBlob(base64Img, contentType);
const blobUrl = URL.createObjectURL(blob);

I get an error because b64toBlob is undefined.

So I had to do the following instead:

import * as b64toBlob from 'b64-to-blob';

const contentType = 'image/png';
const blob = (b64toBlob as any)(base64Img, contentType);
const blobUrl = URL.createObjectURL(blob);

And the typing is not good anymore with that kind of import so I had to type the b64toBlob function as any. Not sure how to deal with that but maybe you'll have an idea :smile:

maxime1992 avatar Mar 23 '18 10:03 maxime1992