2

Im my node + typescript application I have the following code.

 const base64Data = new Buffer.from(url, 'base64');

Here it gives the following error.

'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.

I have installed @types/node. Why am I getting this error? How can I fix this?

Shashika Virajh
  • 8,497
  • 17
  • 59
  • 103

2 Answers2

4

You can fix it by either using

Buffer.from(url, 'base64');

or

new (Buffer.from as any)(url, 'base64');

But, I don't know why this is an issue if you have types installed.

Fahad Farooq
  • 449
  • 5
  • 11
0

new is redundant here, you just need to call Buffer.from(url, 'base64').

There is a deprecated new Buffer(url, 'base64') but it's not recommended to use it.