【发布时间】:2019-06-01 16:44:24
【问题描述】:
安装 jquery 和 @types/jquery 后,我似乎无法让 JQuery 在我的打字稿文件中工作。
如果我使用:
import * as $ from 'jquery';
$("#test").addClass("className");
我在$("#test") 收到以下错误:
TS2349: Cannot invoke an expression whose type lacks a call signature.
如果我按照 WebStorm 的建议将导入更改为:
import $ from 'jquery';
然后没有错误显示,但是在尝试编译文件时出现错误:
error TS1192: Module '"C:/Users/Home/Desktop/react/hello-world/node_modules/@types/jquery/index"' has no default export.
我查看了十几个其他 StackOverFlow 帖子,但没有任何帮助。有什么想法吗?
【问题讨论】:
-
如果我尝试像
$.each([],() => {});这样简单的事情,我仍然会得到 $ 未定义? -
似乎与
import $ from 'jquery';正常工作:stackblitz.com/edit/typescript-2sfodn?file=index.ts -
@Andriy 我认为这与 React transpilation 与 Babel 交互有关
-
从未找到解决方案?
标签: jquery typescript