jquery - 在 Angular 2 应用程序中集成 JQuery 后出现编译错误

标签 jquery angular typescript

我有一个使用 npm 管理的 Angular 2 项目,我最近运行了

typings install dt~jquery --save --global

将 JQuery 类型定义添加到我的项目中。

然后,npm 按预期将该类型定义文件下载到目录 node_modules 中。

现在的问题是 Typescript 编译器(使用 npm run tsc:w)提示:

$ npm run tsc:w

node_modules/@types/jquery/index.d.ts(3246,5): error TS2300: Duplicate identifier 'export='. typings/globals/jquery/index.d.ts(601,5): error TS2374: Duplicate string index signature. typings/globals/jquery/index.d.ts(2850,5): error TS2374: Duplicate string index signature. typings/globals/jquery/index.d.ts(2851,5): error TS2375: Duplicate number index signature. typings/globals/jquery/index.d.ts(3224,5): error TS2300: Duplicate identifier 'export='. 18:48:59 - Compilation complete. Watching for file changes.

有什么想法可以解决这个问题吗?

最佳答案

转换器给出重复定义错误,因为您似乎已将定义文件安装到项目中的多个位置:

node_modules/@types/jquery/index.d.ts
typings/globals/jquery/index.d.ts

尝试通过键入以下行来卸载@types/jquery模块:

npm remove @types/jquery --save-dev

关于jquery - 在 Angular 2 应用程序中集成 JQuery 后出现编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41269009/

相关文章:

php - 使用ajax为每个输入字段更新mysql中的数据

javascript - 返回一系列 creationTimes 中的最近时间

angular - 获取 http://localhost:8000/api net::ERR_CONNECTION_REFUSED

typescript - 在 tsconfig.json 和 tslint.json 中设置规则有什么区别?

javascript - react 路由器dom v5默认路由不起作用

jquery - 简单模态——开启onload

jquery - 将AngularJS扩展到现有的jQuery大量应用程序中

javascript - Angular2 - 动态加载 Ace 编辑器

javascript - Typescript:重写子类中的父类属性

javascript - 使用 javascript 实现下拉菜单更改时的重绘功能