Angular2: Error – Cannot find name ‘many’ and namespace ‘_’ issues with Lodash in Angular2 application using Typescript

Standard

I have consumed lodash in previous project and blogged about it (link)

In the recent project when I updated lodash and typescript to their respective latest version. I start getting error in Visual Studio 2015.

Below is the list of error in VS:

Duplicate identifier '_'.
Cannot find name 'Partial'.
Cannot find namespace '_'.
A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
Cannot find name 'P'.
Cannot find name 'keyof'.
']' expected.
Cannot find name 'T'.
Declaration or statement expected.
A parameter initializer is only allowed in a function or constructor implementation.
Cannot find name 'T'.
']' expected.
')' expected.
Declaration or statement expected.
Cannot find name 'ConformsPredicateObject'.
Cannot find name 'Many'
Package.json:
{
  "name": "pms",
  "version": "1.0.0",
  "scripts": {},
  "license": "ISC",
  "dependencies": {
    "@angular/common": "^2.4.9",
    "@angular/compiler": "^2.4.9",
    "@angular/core": "^2.4.9",
    "@angular/forms": "^2.4.9",
    "@angular/http": "^2.4.9",
    "@angular/platform-browser": "^2.4.9",
    "@angular/platform-browser-dynamic": "^2.4.9",
    "@angular/router": "^3.4.9",
    "@angular/upgrade": "^2.4.9",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.10",
    "rxjs": "^5.2.0",
    "systemjs": "^0.20.9",
    "zone.js": "^0.8.0",
    "lodash": "^4.17.4"
  },
  "devDependencies": {
    "@types/core-js": "^0.9.37",
    "typescript": "^2.2.1",
    "typings": "^2.1.0",
    "@types/lodash": "^4.14.55"
  }
}

 

Solution:

Update @types/lodash in package.json to Typescript 2.0 compatible types in order to use lodash without any issue. Execute the below npm command

> npm install @types/lodash@ts2.0 --save-dev 
Updated Package.json:
{
  "name": "pms",
  "version": "1.0.0",
  "scripts": {},
  "license": "ISC",
  "dependencies": {
    "@angular/common": "^2.4.9",
    "@angular/compiler": "^2.4.9",
    "@angular/core": "^2.4.9",
    "@angular/forms": "^2.4.9",
    "@angular/http": "^2.4.9",
    "@angular/platform-browser": "^2.4.9",
    "@angular/platform-browser-dynamic": "^2.4.9",
    "@angular/router": "^3.4.9",
    "@angular/upgrade": "^2.4.9",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.10",
    "rxjs": "^5.2.0",
    "systemjs": "^0.20.9",
    "zone.js": "^0.8.0",
    "lodash": "^4.17.4"
  },
  "devDependencies": {
    "@types/core-js": "^0.9.37",
    "typescript": "^2.2.1",
    "typings": "^2.1.0",
    "@types/lodash": "ts2.0"
  }
}
Advertisements

One thought on “Angular2: Error – Cannot find name ‘many’ and namespace ‘_’ issues with Lodash in Angular2 application using Typescript

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s