Skip to content

Commit

Permalink
fix: 类型 InfoWindow 缺少 extra data 相关方法
Browse files Browse the repository at this point in the history
  • Loading branch information
xyy94813 committed May 27, 2024
1 parent 14ea4cc commit 0f6b7eb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion types/overlays/InfoWindow.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type InfoWindowEventType = 'open' | 'close';
* 从实现来看,右键菜单作为一个地图覆盖物。很有可能继成自通用 Overlay.
* @docs https://lbs.amap.com/api/javascript-api-v2/documentation#infowindow
*/
export declare class InfoWindow extends Event<InfoWindowEventType> {
export declare class InfoWindow<ExtraData = any> extends Event<InfoWindowEventType> {
constructor(opt?: InfoWindowOptions);
/** 打开信息窗体 */
open(map: Map, pos: LngLatLike, height?: number): void;
Expand All @@ -65,6 +65,15 @@ export declare class InfoWindow extends Event<InfoWindowEventType> {
getAnchor(): string;
/** 设置信息窗体锚点 默认值:'bottom-center'。 */
setAnchor(anchor: InfoWindowOptions['anchor']): void;
/**
* 设置自定义数据
* @param extData 自定义数据
*/
setExtData(extData: ExtraData): void;
/**
* 获取自定义数据
*/
getExtData(): ExtraData;
}

export default InfoWindow;
7 changes: 7 additions & 0 deletions types/overlays/InfoWindow.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ expectAssignable<InfoWindowEventType>('close');

//
const infoWindow = new InfoWindow();
const infoWindow2 = new InfoWindow<{ x: string }>();
expectType<InfoWindow>(infoWindow);
expectType<InfoWindow<{ x: string }>>(infoWindow2);
expectAssignable<Event<InfoWindowEventType>>(infoWindow);

// InfoWindow methods
Expand Down Expand Up @@ -83,3 +85,8 @@ expectType<void>(infoWindow.setAnchor('bottom-left'));
expectType<void>(infoWindow.setAnchor('bottom-center'));
expectType<void>(infoWindow.setAnchor('bottom-right'));
expectType<void>(infoWindow.setAnchor('others new anchor'));

expectType<void>(infoWindow.setExtData({}));
expectType<any>(infoWindow.getExtData());
expectType<void>(infoWindow2.setExtData({ x: 'string' }));
expectType<{ x: string }>(infoWindow2.getExtData());

0 comments on commit 0f6b7eb

Please sign in to comment.