【发布时间】:2018-10-23 07:37:57
【问题描述】:
我在我的 TypeScript 项目中使用 jQuery。我之前有npm install --save-dev @types/jquery。在我的文件中我有import $ from 'jquery'; 然后我有课:
class A {
$el: $
}
PhpStorm 产生错误Cannot find name $。但是,如果我使用 jQuery 作为 $('selector') 之类的构造函数,则不会发生错误。
tsconfig.json:
{
"compilerOptions": {
"lib": ["es2018", "dom"],
"baseUrl": "./src2",
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"types": [
"node"
],
"typeRoots": [
"node_modules/@types"
]
}
我尝试导入jQuery 也喜欢这个import * as $ from 'jquery',import $ = require('jquery');。
jQuery 版本:3.3.1。
【问题讨论】:
-
你也做了 npm install jquery 吗?
-
@Ric 是的,我做到了
-
@Ric 工作!我一直在寻找答案一个小时,并没有找到这篇文章。很可能它不包含我搜索的搜索关键字。
-
@Ric 你可以用这个回答
标签: jquery typescript phpstorm