Currently, I am utilizing TypeScript version 1.4.1 for a project setup like this:
scripts/
libs/
jquery/
jquery.d.ts // Latest from DefinitelyTyped
jquery.js // 2.1.3
lodash/
lodash.d.ts // Latest from DefinitelyTyped
lodash.js // 3.3.1
main/
test.ts
The content of my main/test.ts file is as follows:
/// <reference path="../libs/lodash/lodash.d.ts" />
/// <reference path="../libs/jquery/jquery.d.ts" />
import _ = require("lodash");
import $ = require("jquery");
function requireExistingElement($el: $.JQuery) {
if(_.isUndefined($el) || _.isNull($el) || $el.length === 0) {
throw new Error("It seems the requested element does not exist?");
}
}
requireExistingElement($("body"));
Upon compiling with the command below:
tsc --module amd scripts/main/test.ts
Although I anticipate a successful run, the compilation gives me the following errors:
scripts/main/test.ts(7,38): error TS2304: Cannot find name '$'.
scripts/main/test.ts(13,24): error TS2304: Cannot find name '$'.
Hence, my query is: How do I reference jQuery correctly since the above method is not functioning? Or, could there be an error in my approach?