查看类型定义时,@types/leaflet您会看到定义的自定义控件,类似于:
export namespace Control {
...
class Zoom extends Control {
constructor(options?: ZoomOptions);
options: ZoomOptions;
}
...
}
Run Code Online (Sandbox Code Playgroud)
但是,通过以下方式创建自定义控件时:
declare module 'leaflet' {
namespace Control {
class CustomControl extends Control {
constructor(options: CustomOptions);
}
}
namespace control {
function customControl(options: CustomOptions): Control.CustomControl;
}
}
L.Control.CustomControl = L.Control.extend({
...
});
Run Code Online (Sandbox Code Playgroud)
引发打字错误:
Type '(new (...args: any[]) => any) & typeof Class' is missing the following properties from type 'typeof CustomControl': Zoom, Attribution, Layers, Scale, and 6 more.
这似乎是由于名称空间和类Control通过Typescript的声明合并而发生的。这导致 …