Using Lodash with Ionic 2

I just started my first Ionic 2 application and struggled with adding Lodash as dependency. Since TypeScript 2 adding npm dependencies should be that easy:

npm install --save @types/lodash

You don’t have to deal with other tools like typings anymore. However the next build failed with this transpile error:

[12:06:18] transpile started …
[12:06:44] typescript: node_modules/@types/lodash/index.d.ts, line: 11444
‘]’ expected.

The problem is that the current version of the declaration file expects TypeScript 2.1 whereas Ionic 2 is using TypeScript 2.0. You need to search for a matching version and install the correct one:

npm view @types/lodash # check the dist-tags
npm install --save --save-exact @types/lodash@ts2.0

Don’t forget the save-exact flag. Otherwise your coworkers will run in the same problem after fetching.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.