Sto usando dattiloscritto 1.4.1, e avere un progetto disposti in questo modo:
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
miei principali/test.ts contiene quanto segue:
/// <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"));
Questa è compilato con il seguente comando :
tsc --module amd scripts/main/test.ts
mi aspetto che questo per funzionare correttamente, ma quando compilo io ottenere:
scripts/main/test.ts(7,38): error TS2304: Cannot find name '$'.
scripts/main/test.ts(13,24): error TS2304: Cannot find name '$'.
La mia domanda è: come faccio riferimento jquery dato che quanto sopra non funziona? O sto solo facendo qualcosa di sbagliato?
Hai ragione, questo era il problema. Sembra molto non ovvio, ma ha senso. Grazie! – Smartboy