5
我用的打字稿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
我主/ 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"));
這是用下面的命令編譯:
tsc --module amd scripts/main/test.ts
我希望這能正常運行,但是當我編譯它,我得到:
scripts/main/test.ts(7,38): error TS2304: Cannot find name '$'.
scripts/main/test.ts(13,24): error TS2304: Cannot find name '$'.
我的問題是:我如何引用jQuery給定上述不工作?或者,我只是做錯了什麼?
你說得對,那是問題所在。這看起來很不明顯,但它確實有道理。謝謝! – Smartboy 2015-03-02 22:33:41