带有Typescript的Jquery:’ElementFinder’类型中不存在属性’css’

我正在尝试在我的angular2项目中使用jquery,它正在使用webpack进行构建。 我从这里得到了webpack angular2入门套件: 这里

但是,由于我的构建失败,我无法弄清楚如何摆脱这些错误。

这是我的typings.json

{ "globalDependencies": { "angular-protractor": "registry:dt/angular-protractor#1.5.0+20160425143459", "angular2-beta-to-rc-alias": "file:./node_modules/@angularclass/angular2-beta-to-rc-alias/src/beta-17/typings.d.ts", "core-js": "registry:dt/core-js#0.0.0+20160317120654", "hammerjs": "registry:dt/hammerjs#2.0.4+20160417130828", "jasmine": "registry:dt/jasmine#2.2.0+20160505161446", "jquery": "github:DefinitelyTyped/DefinitelyTyped/jquery/jquery.d.ts#7de6c3dd94feaeb21f20054b9f30d5dabc5efabd", "node": "registry:dt/node#6.0.0+20160514165920", "selenium-webdriver": "registry:dt/selenium-webdriver#2.44.0+20160317120654", "source-map": "registry:dt/source-map#0.0.0+20160317120654", "uglify-js": "registry:dt/uglify-js#2.6.1+20160316155526", "webpack": "registry:dt/webpack#1.12.9+20160321060707" } } 

我试过了 :

  typings install dt~jquery --global --save 

同样,但错误仍然存​​在:

  Property 'css' does not exist on type 'ElementFinder'. 

而且:

  Subsequent variable declarations must have the same type. Variable '$' must be of type 'cssSelectorHelper', but here has type 'JQueryStatic'. 

你需要定义jQuery类型,我正在使用:

https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/jquery/jquery.d.ts

它对我来说很好。

我有同样的问题,我不得不自己下载这个打字机并把它放在我的文件夹里。

然后在你的tsconfig.js中

  "files": [ "./src/app/**/*.ts", "./src/platform/**/*.ts", "!./node_modules/**", "./src/custom-typings.d.ts", "./src/jquery-typings-custom/index.d.ts", !!!!!!! This is the folder where I put those typings downloaded from the url "./src/vendor/slick/slick-typings.d.ts", "./typings/index.d.ts" ], 

然后,在你的一个组件(可能是根组件,通常是app.ts)中,你应该这样做:

  declare var jQuery : JQueryStatic; 

然后你不应该使用$,而应该开始使用jQuery(这个问题也有一个解决方法,但我并不在意)。