在导入jquery后,Typescript找不到名字'$'?

Sma*_*boy 5 jquery typescript

我正在使用TypeScript 1.4.1,并且项目布局如下:

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
Run Code Online (Sandbox Code Playgroud)

我的main/test.ts包含以下内容:

/// <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 appears the requested element does not exist?");
    }
}

requireExistingElement($("body"));
Run Code Online (Sandbox Code Playgroud)

这是使用以下命令编译的:

tsc --module amd scripts/main/test.ts
Run Code Online (Sandbox Code Playgroud)

我希望它能正确运行,但是当我编译它时,我得到:

scripts/main/test.ts(7,38): error TS2304: Cannot find name '$'.
scripts/main/test.ts(13,24): error TS2304: Cannot find name '$'.
Run Code Online (Sandbox Code Playgroud)

我的问题是:如果上述不起作用,我如何引用jquery?或者,我只是做错了什么?

cur*_*rpa 5

改变($el: $.JQuery)($el: JQuery)

$是一个变量,因此不能在类型注释中使用.JQuery是一个接口,因此可以在类型注释中使用.