我正在使用 typescript 和 jquery,但我不断得到
Uncaught TypeError: $ is not a function
有人见过这个吗?
我正在将 typescript 编译为 ES2017,然后使用 webpack 转换为 ES5。
//tsconfig
{
"compileOnSave": true,
"compilerOptions": {
"module": "es2015",
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true,
"target": "es2017",
"noImplicitAny": false,
"outDir": "Output",
"esModuleInterop": true
}
}
如何使用 jquery
import * as $ from "jquery";
var form = $(document.createElement('form'));
但后来我明白了
最佳答案
找到了解决方案。要使用 $ 作为函数,我必须从 jquery npm 模块导入默认值。有了这个 import 语句,它就可以工作了。
import $ from "jquery";
我还必须在 tsconfig.json 中打开此功能
"allowSyntheticDefaultImports": true
关于javascript - Typescript 和 Jquery 导入 - $ 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48673975/