Michael Commons
Michael Commons

Reputation: 822

Lodash in Visual Studio HTML Typescript application

I'm trying to make a new HTML App with Typescript. I installed the following plugin for Typescript : Visual studio TypeScript

Now, using Nuget, i installed lodash, the packages config looks like:<?xml version="1.0" encoding="utf-8"?><packages><package id="lodash" version="4.13.1" targetFramework="net452" /></packages>, so , it seems that the Lodash is installed. A new folder is added in my solution : Scripts, with the following .js-es :

lodash.core.js , lodash.core.min.js , lodash.js, lodash.min.js

In the .ts file i have an array :

var users = [
{ 'user': 'barney', 'age': 36, 'active': true },
{ 'user': 'fred', 'age': 40, 'active': false },
{ 'user': 'pebbles', 'age': 1, 'active': true }
];

I want to try this lodash function :_.findKey(users, function(o) { return o.age < 40; }); // → 'barney' (iteration order is not guaranteed)

The intellisense doesn't have any suggestion for _. typing.

Any help? Thanks

Upvotes: 0

Views: 640

Answers (1)

invernomuto
invernomuto

Reputation: 10211

You have to install(via Nuget or manually) also the definition type for Lodash: https://www.nuget.org/packages/lodash.TypeScript.DefinitelyTyped/

Quote from https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html

When using an external JavaScript library, or new host API, you’ll need to use a declaration file (.d.ts) to describe the shape of that library.

...then you have to declare a reference to the definition on top of your file:

/// <reference path="../typings/insertheredefinitionfilename.ts"/>

Quote from https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html

Triple-slash directives are single-line comments containing a single XML tag. The contents of the comment are used as compiler directives. The /// <reference path="..." /> directive is the most common of this group. It serves as a declaration of dependency between files.

Triple-slash references instruct the compiler to include additional files in the compilation process.

Upvotes: 1

Related Questions