我想在此文件中扩展名称空间google.maps
中定义的类:
@类型/谷歌地图/ index.d.ts
class MyMarker extends google.maps.Marker {
constructor(options: google.maps.MarkerOptions){
super(options);
}
}
这种情况没有错误。但是在运行时,我在构造函数中出现错误,因为google.maps
全局仍未定义。
我做错了什么?
答案 0 :(得分:1)
您需要先导入它,例如
HELO
答案 1 :(得分:0)
interface
代替class
并做一堆TS类型体操。它有效,但不是最佳......
// new google.maps.Marker for MarkerClusterer
export interface UuidMarker extends Marker {
uuid: string;
}
/**
* Hack: "extend" google.maps.Marker to include uuid property
* guard with this.ready.then() to ensure google.maps is loaded
*/
function UuidMarkerFactory(uuid: string, options?: MarkerOptions) : Promise<UuidMarker> {
return this.ready.then( ()=>{
let gmOptions = options as any as google.maps.MarkerOptions;
const marker = new google.maps.Marker( gmOptions );
marker['uuid'] = uuid;
return marker as any as UuidMarker;
})
}