私はjqueryでtypescriptをテストしていますが、test.tsファイルをコンパイルすると常にエラーが表示されます。
私はすでにjquery &をインポートして定義リファレンスを追加しました。 test.ts
ファイルにimport $ = require("jquery")
を使用すると、tsc
のコンパイル時に別のエラー "Cannot find module jquery
"が発生します。ただし、JQueryフォルダーはすでにnode_modulesフォルダー内に存在します。
typescriptでjqueryを使用する正しい方法は何ですか?
以下は私の手順です:
- は
npm install jquery --save
- を使用してjqueryのをインストールし
typings install --global --save dt~jquery
- を使用してタイピング& jqueryの定義をインストールtest.ts
/// <reference path="../../../typings/globals/jquery/index.d.ts" />
のTSconfigの上部にjqueryの参照を追加します。 .json
{
"compilerOptions": {
"jsx": "react",
"outDir": "./dist",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"experimentalDecorators": true
},
"exclude": [
"node_modules"
],
"files": [
"./typings/index.d.ts",
"./src/wo/tests/test.ts",
]
}
test.ts
/// <reference path="../../../typings/globals/jquery/index.d.ts" />
let test:any=$("div");
どのようにプロジェクトをコンパイルしますか?また、あなたの 'tsconfig.json'定義が間違っているようです。あなたは 'exclude'と' files'の両方を使うことはできません( 'files'はこの場合勝つので、おそらくパスは間違っています)。また、 'tsconfig.json'が –