Używam maszynopis 1.4.1 i mieć projekt rozplanowany tak:
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
mój główny/test.ts zawiera następujące elementy:
/// <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"));
ten jest skompilowany za pomocą następującego polecenia :
tsc --module amd scripts/main/test.ts
oczekuję, że działa poprawnie, ale kiedy go skompilować uzyskać:
scripts/main/test.ts(7,38): error TS2304: Cannot find name '$'.
scripts/main/test.ts(13,24): error TS2304: Cannot find name '$'.
Moje pytanie brzmi: Jak odwołać się do jquery, biorąc pod uwagę, że powyższe nie działa? Czy po prostu robię coś nie tak?
Masz rację, to był problem. Wydaje się to bardzo nieoczywiste, ale ma sens. Dzięki! – Smartboy