我最近接触过TypeScript,但我对文档有点挣扎.似乎是相当多的草根方法.案例和观点.
获取JS库的定义.
首先,如果你从NuGet获得js文件那部分nuget包应该是一个d.ts文件.
其次,我无法找到有关如何创建定义文件的任何特定文档.
我想要包含MarkerWithLabel库,它是google.maps api库的扩展.
有没有人有他们愿意分享的.d.ts文件,或者我在哪里可以获得有关如何从JS库创建/生成文件的文档.
编辑:我正在寻找这个d.ts文件的库是MarkerWithLabel.
这是我基于spec doc开始构建的.d.ts文件,但这似乎根本不起作用.
/// <reference path="google.maps.d.ts"/>
declare class MarkerWithLabelOptions {
crossImage: string;
handCursor: string;
labelAnchor: google.maps.Point;
labelClass: string;
labelContent: any;
labelInBackground: boolean;
labelStyle: any;
labelVisible: boolean;
optimized: boolean;
raiseOnDrag: boolean;
}
declare class MarkerWithLabel extends google.maps.Marker{
constructor(opt?: MarkerWithLabelOptions);
}
Run Code Online (Sandbox Code Playgroud)
实施如下:
var _mwlo =new MarkerWithLabelOptions({
position: this.CenterPoint.toLatLng()
, draggable: true
, map: this._map
, labelAnchor: new google.maps.Point(22, 0)
, labelStyle: {opacity: 1.0}
});
var _mwl = new MarkerWithLabel(_mwlo);
Run Code Online (Sandbox Code Playgroud)
我得到一个错误,它说它找不到与提供的参数匹配的方法.
我最终解决了这个问题,并为其他人提供了工作计划.它可能是理想的,但似乎有效.¯\ _(ツ)_ /¯
/// <reference path="google.maps.d.ts"/>
declare class MarkerWithLabelOptions extends MarkerWithLabel {
constructor();
crossImage: string;
handCursor: string;
labelAnchor: any;
labelClass: string;
labelContent: any;
labelInBackground: boolean;
labelStyle: any;
labelVisible: boolean;
optimized: boolean;
raiseOnDrag: boolean;
position: any;
}
declare class MarkerWithLabel extends google.maps.Marker {
constructor(opts?:any);
crossImage: string;
handCursor: string;
labelAnchor: any;
labelClass: string;
labelContent: any;
labelInBackground: boolean;
labelStyle: any;
labelVisible: boolean;
optimized: boolean;
raiseOnDrag: boolean;
}
Run Code Online (Sandbox Code Playgroud)
您可能需要为解决方案适当更新参考路径.
| 归档时间: |
|
| 查看次数: |
3467 次 |
| 最近记录: |