Home > Net >  Can we use Buffer.from in typescript frontend code
Can we use Buffer.from in typescript frontend code

Time:02-24

Can we use Buffer.from to Base 64 encode a string in a front end typescript application. Using btoa() is showing as deprecated.

CodePudding user response:

No you cannot. Buffer is a Node.js specific class and it does not exist in browsers.

CodePudding user response:

The warning is beacause you have node types in your proyect, so Typescript Compiler thinks that you're using atob in node (which is totally deprecated) but you don't. You are totally fine using atob in front-end.

To solve the warning you can remove node types (if you're not using them), or to make it simple, a comentary before your atob call should be enought to avoid any warning from the next line:

// @ts-ignore
Your atob call goes here

Make sure you keep it simple under the @ts-ignore, you don't want to hidde a real problem there.

  • Related