【发布时间】:2018-08-01 03:05:19
【问题描述】:
我在我的项目中使用最新的传单@types (v1.2.5),但这些不符合最新版本的传单 (1.3.x)
特别是,他们的 LayerGroup 接口不包含 setZIndex 属性,因此我想进一步扩展接口以包含它,以便我可以在我的 TS 源中调用该函数。
LayerGroup 的类型定义目前如下所示:
declare namespace L {
/**
* Create a layer group, optionally given an initial set of layers.
*/
function layerGroup<T extends ILayer>(layers?: T[]): LayerGroup<T>;
export interface LayerGroupStatic extends ClassStatic {
/**
* Create a layer group, optionally given an initial set of layers.
*/
new<T extends ILayer>(layers?: T[]): LayerGroup<T>;
}
export var LayerGroup: LayerGroupStatic;
export interface LayerGroup<T extends ILayer> extends ILayer {
/**
* Adds the group of layers to the map.
*/
addTo(map: Map): LayerGroup<T>;
/**
* Adds a given layer to the group.
*/
addLayer(layer: T): LayerGroup<T>;
/**
* Removes a given layer from the group.
*/
removeLayer(layer: T): LayerGroup<T>;
/**
* Removes a given layer of the given id from the group.
*/
removeLayer(id: string): LayerGroup<T>;
/**
* Returns true if the given layer is currently added to the group.
*/
hasLayer(layer: T): boolean;
/**
* Returns the layer with the given id.
*/
getLayer(id: string): T;
/**
* Returns an array of all the layers added to the group.
*/
getLayers(): T[];
/**
* Removes all the layers from the group.
*/
clearLayers(): LayerGroup<T>;
/**
* Iterates over the layers of the group, optionally specifying context of
* the iterator function.
*/
eachLayer(fn: (layer: T) => void, context?: any): LayerGroup<T>;
/**
* Returns a GeoJSON representation of the layer group (GeoJSON FeatureCollection).
* Note: Descendent classes MultiPolygon & MultiPolyLine return `Feature`s, not `FeatureCollection`s
*/
toGeoJSON(): GeoJSON.FeatureCollection<GeoJSON.GeometryObject>|GeoJSON.Feature<GeoJSON.MultiLineString|GeoJSON.MultiPolygon>;
////////////
////////////
/**
* Should contain code that creates DOM elements for the overlay, adds them
* to map panes where they should belong and puts listeners on relevant map events.
* Called on map.addLayer(layer).
*/
onAdd(map: Map): void;
/**
* Should contain all clean up code that removes the overlay's elements from
* the DOM and removes listeners previously added in onAdd. Called on map.removeLayer(layer).
*/
onRemove(map: Map): void;
}
}
我是否可以在我的项目中添加另一个类型定义来提供缺少的属性?
我知道我可以提出拉取请求以将其添加到 @types 存储库中,但与此同时,为了解除对开发的阻碍,我希望我可以使用一些临时的东西
【问题讨论】:
标签: typescript leaflet typescript-typings