Node typescript lacks a construct signature (new Buffer)

Viewed 311

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?

2 Answers

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.

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.

Related