Tag: 打字稿

Typescript和JQuery编译错误:找不到名字’$’

我正在用jquery测试typescript,但是当我编译test.ts文件时,它总是给我一个错误,指出:找不到名字’$’。 我已经导入了jquery并添加了它的定义参考。 如果我在test.ts文件中使用import $ = require(“jquery”) , test.ts在进行tsc编译时会出现另一个错误“ Cannot find module jquery ”。 但是,JQuery文件夹已存在于node_modules文件夹中。 有谁知道在打字稿中使用jquery的正确方法是什么? 以下是我的步骤: 使用npm install jquery –save 使用typings install –global –save dt~jquery和jquery定义 在test.ts的顶部添加jquery引用/// tsconfig.json { “compilerOptions”: { “jsx”: “react”, “outDir”: “./dist”, “sourceMap”: true, “noImplicitAny”: true, “module”: “commonjs”, “target”: “es5”, “experimentalDecorators”: true }, “exclude”: [ “node_modules” ], “files”: [ “./typings/index.d.ts”, “./src/wo/tests/test.ts”, ] } […]

带有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 […]

在jquery函数范围内的类上的TypeScript调用方法

我有下面的TypeScript类。 export class BrandViewModel { private _items = ko.observableArray(); public Add(id: number, name: string, active: boolean) : void { this._items.push(new BrandItem(this, id, name, active)); } public Get() : void { $.get(“/api/brand”, function(items) { $.each(items, function (i, item) { this.Add(item.Id, item.Name, item.Active); }); }, “json”); } } Get方法生成的javascript是: BrandViewModel.prototype.Get = function () { $.get(“/api/brand”, function (items) […]

“JqueryStatic”类型的值不可调用

我正在开发一个打字稿项目。 当我调用“$”时,编辑器说“类型’JqueryStatic’的值不可调用。” 我安装了jquery.definetelyTyped包,我也引用了jquery.d.ts文件。

我们如何使用typescript创建自定义jquery插件?

我需要在我的应用程序中使用jquery自定义插件,如何使用typescript创建自定义jquery插件。 我google了很多,我只是在链接下面 http://typescript.codeplex.com/discussions/398401 在TypeScript中定义自定义jQuery UI小部件 上面的链接使用普通的javascript代码,但javascript代码将在typescript中工作,但问题是我不能在这个插件中使用typescript类。 有没有办法在jquery插件中使用typescript类,否则有任何其他方法在typescript中创建jquery插件。 任何建议都应该受到赞赏。

在ajax .done中为函数提供了哪些参数?

我有以下内容: $.ajax(link.href, { cache: false, dataType: ‘html’ }) .done(onDialogDone) .fail(onDialogFail); 这工作正常,并调用onDialogDone。 但是,我希望看到哪些参数提供给onDialogDone,以及我期望在onDialogFail中看到什么。 我问的原因是因为我使用的是typescript,我想在定义onDialogDone和onDialogFail时提供正确的参数。

初始化JQuery日期选择器

我有以下代码 $.datepicker.setDefaults({ dateFormat: ‘dd/mm/yy’ }); var searchStartDate = moment(($(‘#searchStart’)).datepicker(‘getDate’)); var searchEndDate = moment(($(‘#searchEnd’)).datepicker(‘getDate’)); 我在第一行的datepicker上收到错误: 属性“datepicker”在“JQueryStatic”类型的值上不存在 有人能指出我正确的方向来解决它吗?

错误TS2339:类型’JQuery’上不存在属性’modal’

我正在使用带有AngularJS的Typescript。 我使用jQuery库的类型定义的模态有问题。 我收到以下错误:’错误TS2339:类型’JQuery’上不存在属性’模态’。 版本:jQuery库,版本1.10.x / 2.0.x说明: https : //github.com/borisyankov/DefinitelyTyped 码 $scope.delete = function (id) { Photo.get({id: id}, function(result) { $scope.photo = result; $(‘#deletePhotoConfirmation’).modal(‘show’);// error line }); }; 我在jquery.d.ts中引用了angular.d.ts 我的全球供应商参考文件如下所示:

带有var args的Typescript 0.9.5编译失败

所以我试图在我们的项目中升级到typescript 0.9.5,但我目前卡住了。 这是从编译器中恢复的错误: error TS2082: Supplied parameters do not match any signature of call target: Call signatures of types ‘(event: JQueryEventObject, component: any, mouseClickPagePosition: any) => void’ and ‘(eventObject: JQueryEventObject, …args: any[]) => any’ are incompatible: Call signature expects 1 or fewer parameters. 好像这段代码: jQuery(‘selector’).on(‘event’, (event, component, mouseClickPagePosition) => { // code }); 不能与此jQuery定义一起使用: on(events: […]

如何在TypeScript中处理内置对象的专有/自定义属性的警告

我正在使用依赖于专有属性navigator.id Personas。 由于此属性不是标准属性,因此TypeScript编译器会生成以下警告: $ tsc home.ts –out my_ts_generated_code.js /Users/…./home.ts(27,18): The property ‘id’ does not exist on value of type ‘Navigator’ 但.js文件已成功生成并在FF15浏览器上运行,没有任何警告/错误消息。 我还按照文档的说明为navigator.id添加了一个polyfill,因此navigator.id肯定会在每个浏览器中都可用。 有人可以建议我如何处理这个警告吗? 的index.html Sign in Sign out home.ts declare var $; class Student { fullname : string; constructor(public firstname, public middleinitial, public lastname) { this.fullname = firstname + ” ” + middleinitial + ” […]