Angular: install and configure underscore

Install and configure underscore library in your Angular project

Import libraries from command line

npm install underscore --save
npm install @types/underscore --save

Add the following array to the tsconfig.app.json

"types": [
  "underscore"
]

In order to use underscore, import the following all modules

import * as _ from 'underscore';

And finally, use underscore in your class

var sum = _.reduce([1, 2, 3], function(memo, num){ return memo + num; }, 0);