Angular Cli全局jquery:TS2304:找不到名称'$';
全局使用jquery和jquery插件时。ng编译器出现以下错误:Angular Cli全局jquery:TS2304:找不到名称'$';,jquery,angular,plugins,angular-cli,typescript-typings,Jquery,Angular,Plugins,Angular Cli,Typescript Typings,全局使用jquery和jquery插件时。ng编译器出现以下错误: TS2304: Cannot find name '$'. vscode成功地识别了tsconfig中定义的全局键入。尽管编译器抛出错误,但它仍然成功地全局加载插件。是否可以抑制此错误 解决方案1: import*作为$from'jquery' 这不是一个可行的解决方案,因为这样一来,jquery插件中的键入就不再在vscode中可用 配置 tsconfig: "typeRoots": [ "node_module
TS2304: Cannot find name '$'.
vscode
成功地识别了tsconfig
中定义的全局键入。尽管编译器抛出错误,但它仍然成功地全局加载插件。是否可以抑制此错误
解决方案1:
import*作为$from'jquery'
这不是一个可行的解决方案,因为这样一来,jquery插件中的键入就不再在vscode
中可用
配置
tsconfig:
"typeRoots": [
"node_modules/@types" // where jquery is also installed
],
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/datatables.net/js/jquery.dataTables.js",
"../node_modules/datatables.net-bs/js/dataTables.bootstrap.js"
],
角度cli:
"typeRoots": [
"node_modules/@types" // where jquery is also installed
],
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/datatables.net/js/jquery.dataTables.js",
"../node_modules/datatables.net-bs/js/dataTables.bootstrap.js"
],
结果是typeroot
不够。只需直接为数据表添加类型
。为什么要使用JQuery?声明var$:JQueryStatic代码>@trichetriche,因为datatables需要它,并且是唯一具有灵活性和特性I的表组件need@David你会在哪里申报?jquery类型已经声明了这一点,因此为什么vscode会在使用它的组件之前找到它