问题描述
有许多解决类似问题的线程,但据我所知,这是唯一的.
There are many threads for similar issues, but as far as I can tell this one is unique.
我在我的应用程序中使用 jQuery Address 插件,并希望使用它在TypeScript文件中.不幸的是,该库没有 DefinitelyTyped 脚本.当我尝试使用jQuery.address时,我得到:
I'm using jQuery Address plugin in my app and would like to use it in a TypeScript file. Unfortunately there is no DefinitelyTyped script available for the library. When I try to use jQuery.address, I get:
The property 'address' does not exist on value of type 'jQueryStatic'
每个此线程,我试图在jquery.d.ts
内定义address
:
Per this thread, I've tried to define address
inside of jquery.d.ts
:
interface JQueryStatic {
address(options): any;
...
}
我认为这似乎适用于$ .address();.但不适用于任何地址方式.我还尝试根据此线程创建自己的.d.ts文件,但还是没有运气.我尝试在.d.ts文件中使用declare
.没有运气.
And I think this seems to work for $.address(); but not for any of address' methods. I've also tried to create my own .d.ts file per this thread, but still no luck. And I tried using declare
in a .d.ts file. No luck.
我唯一需要使用的方法是parameter
方法...
The only method that I need to use is the parameter
method...
$.address.parameter('param', 1);
在这种情况下,我会得到:
In which case I get:
The property 'parameter' does not exist on value of type 'address'
关于如何解决此问题的任何想法?
Any ideas on how I can resolve this?
如果有帮助,我正在Visual Studio C#.net环境中工作.
edit: I'm working in a Visual Studio C# .net environment, if that helps.
推荐答案
您不需要编辑jquery.d.ts
本身;将这些定义放在自己的文件中,以便可以正确维护它们.最小的东西是这样的:
You should not need to edit jquery.d.ts
itself; put these definitions in their own file so they can be maintained properly. Something minimal would be like this:
// For methods on e.g. $('a')
interface JQuery {
address(callback?: () => void): JQuery;
}
// For methods on $
interface JQueryStatic {
address: JQueryAddressStatic;
}
interface JQueryAddressStatic {
(): JQuery;
parameter(name: string): string;
parameter(name: string, value: string, append?: boolean): JQuery;
}
这篇关于声明用于TypeScript的JS库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!