I recently converted my hybrid AngularJS app to use TypeScript and SystemJS for module loading. However, I encountered an error in VS2015 related to Lodash:
'Cannot find name '_'
Despite trying various solutions from Stack Overflow such as:
Importing lodash into angular2 + typescript application
Angular2 and lodash...Cannot find name
I am still unable to resolve the issue. The suggestion to add 'import * as _ from "lodash";' only resulted in 'Cannot find module 'lodash'' error.
Even using 'import "lodash";' did not solve the problem and I still get 'Cannot find name '_' error.'
Is there a way to separately assign '_' in my code to fix this? I would like to understand why 'import * as _ from "lodash";' is causing issues with module loading and assignment of '_'. Here is the section of code where the error occurs:
import "lodash";
(function () {
var controller = function (dependency1, dependency2) {
this.myFunction = (myParam) => {
this.MyService.getMyModel(myParam).then((model) => {
this.model = model.Content;
// can I assign _ so that it works here - if so where and how?
_.each(this.model.MyEntities, function (m) { return m.showDetails = false; });
....
My tsconfig.json compiler options are set as follows:
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"lib": [ "es2015", "dom" ]
....
It seems that my project is compiled using tsc v2.6.2 despite having TypeScript 1.8 installed on VS2015. Any insights on this discrepancy?