我试图为地理完整的.d.ts插件编写jQuery文件。我是TypeScript的新手。我在我的.d.ts文件中添加了以下内容:
/// <reference path="jquery.d.ts"/>
interface GeoOptions {
map: string,
mapOptions? : MapOption,
}
interface MapOption extends GeoOptions {
zoom : number
}
interface JQuery {
geocomplete(): JQuery;
geocomplete(options: GeoOptions): JQuery;
}但是我不能像这样初始化插件
$('#geomap').geocomplete(
{
map: ".map",
mapOption: { zoom: 10 },
});我的代码有什么问题?
发布于 2015-12-16 08:08:39
问题在您的interface jQuery中,因为jQuery只是变量,您不能重新声明接口,jquery.d.ts文件说,jQuery是带有jQueryStatic类型的变量。因此,我们需要重新声明jQueryStatic而不是jQuery。
所以,亲爱的朋友,我今天花了更多的时间给你,写了你需要的东西)
/// <reference path="jquery.d.ts"/>
interface GeoOptions {
map: string,
mapOptions? : MapOption,
}
interface MapOption extends GeoOptions {
zoom : number
}
interface JQueryStatic {
geocomplete():JQueryStatic;
geocomplete(options:GeoOptions):JQueryStatic;
}
declare var jQuery: JQueryStatic;
declare var $: JQueryStatic;
jQuery.geocomplete();
$.geocomplete();现在,它应该完美地工作!享受吧!
https://stackoverflow.com/questions/34305181
复制相似问题