From d3ecd9555476a18f05cafe1a6d0cc4f7951ced76 Mon Sep 17 00:00:00 2001 From: CyberFoxHax Date: Thu, 29 May 2014 17:55:13 +0200 Subject: [PATCH 1/2] Generics I have to ask why collection layers aren't generic. --- leaflet/leaflet.d.ts | 82 ++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/leaflet/leaflet.d.ts b/leaflet/leaflet.d.ts index a2d91032aa..c3e5ce8c57 100644 --- a/leaflet/leaflet.d.ts +++ b/leaflet/leaflet.d.ts @@ -474,7 +474,7 @@ declare module L { * positions. * Default value: 'topright'. */ - position: string; + position?: string; } } @@ -773,20 +773,20 @@ declare module L { /** * Create a layer group, optionally given an initial set of layers. */ - function featureGroup(layers?: ILayer[]): FeatureGroup; + function featureGroup(layers?: T[]): FeatureGroup; - export class FeatureGroup extends LayerGroup implements ILayer, IEventPowered { + export class FeatureGroup extends LayerGroup implements ILayer, IEventPowered> { /** * Create a layer group, optionally given an initial set of layers. */ - constructor(layers?: ILayer[]); + constructor(layers?: T[]); /** * Binds a popup with a particular HTML content to a click on any layer from the * group that has a bindPopup method. */ - bindPopup(htmlContent: string, options?: PopupOptions): FeatureGroup; + bindPopup(htmlContent: string, options?: PopupOptions): FeatureGroup; /** * Returns the LatLngBounds of the Feature Group (created from bounds and coordinates @@ -797,17 +797,17 @@ declare module L { /** * Sets the given path options to each layer of the group that has a setStyle method. */ - setStyle(style: PathOptions): FeatureGroup; + setStyle(style: PathOptions): FeatureGroup; /** * Brings the layer group to the top of all other layers. */ - bringToFront(): FeatureGroup; + bringToFront(): FeatureGroup; /** * Brings the layer group to the bottom of all other layers. */ - bringToBack(): FeatureGroup; + bringToBack(): FeatureGroup; //////////// //////////// @@ -826,20 +826,20 @@ declare module L { //////////////// //////////////// - addEventListener(type: string, fn: (e: LeafletEvent) => void, context?: any): FeatureGroup; - addOneTimeEventListener(type: string, fn: (e: LeafletEvent) => void, context?: any): FeatureGroup; - removeEventListener(type: string, fn?: (e: LeafletEvent) => void, context?: any): FeatureGroup; + addEventListener(type: string, fn: (e: LeafletEvent) => void, context?: any): FeatureGroup; + addOneTimeEventListener(type: string, fn: (e: LeafletEvent) => void, context?: any): FeatureGroup; + removeEventListener(type: string, fn?: (e: LeafletEvent) => void, context?: any): FeatureGroup; hasEventListeners(type: string): boolean; - fireEvent(type: string, data?: any): FeatureGroup; - on(type: string, fn: (e: LeafletEvent) => void, context?: any): FeatureGroup; - once(type: string, fn: (e: LeafletEvent) => void, context?: any): FeatureGroup; - off(type: string, fn?: (e: LeafletEvent) => void, context?: any): FeatureGroup; - fire(type: string, data?: any): FeatureGroup; - addEventListener(eventMap: any, context?: any): FeatureGroup; - removeEventListener(eventMap?: any, context?: any): FeatureGroup; - clearAllEventListeners(): FeatureGroup; - on(eventMap: any, context?: any): FeatureGroup; - off(eventMap?: any, context?: any): FeatureGroup; + fireEvent(type: string, data?: any): FeatureGroup; + on(type: string, fn: (e: LeafletEvent) => void, context?: any): FeatureGroup; + once(type: string, fn: (e: LeafletEvent) => void, context?: any): FeatureGroup; + off(type: string, fn?: (e: LeafletEvent) => void, context?: any): FeatureGroup; + fire(type: string, data?: any): FeatureGroup; + addEventListener(eventMap: any, context?: any): FeatureGroup; + removeEventListener(eventMap?: any, context?: any): FeatureGroup; + clearAllEventListeners(): FeatureGroup; + on(eventMap: any, context?: any): FeatureGroup; + off(eventMap?: any, context?: any): FeatureGroup; } } @@ -882,7 +882,7 @@ declare module L { */ function geoJson(geojson?: any, options?: GeoJSONOptions): GeoJSON; - export class GeoJSON extends FeatureGroup { + export class GeoJSON extends FeatureGroup { /** * Creates a GeoJSON layer. Optionally accepts an object in GeoJSON format @@ -1539,34 +1539,34 @@ declare module L { /** * Create a layer group, optionally given an initial set of layers. */ - function layerGroup(layers?: ILayer[]): LayerGroup; + function layerGroup(layers?: T[]): LayerGroup; - export class LayerGroup extends Class implements ILayer { + export class LayerGroup extends Class implements ILayer { /** * Create a layer group, optionally given an initial set of layers. */ - constructor(layers?: ILayer[]); + constructor(layers?: T[]); /** * Adds the group of layers to the map. */ - addTo(map: Map): LayerGroup; + addTo(map: Map): LayerGroup; /** * Adds a given layer to the group. */ - addLayer(layer: ILayer): LayerGroup; + addLayer(layer: ILayer): LayerGroup; /** * Removes a given layer from the group. */ - removeLayer(layer: ILayer): LayerGroup; + removeLayer(layer: ILayer): LayerGroup; /** * Removes a given layer of the given id from the group. */ - removeLayer(id: string): LayerGroup; + removeLayer(id: string): LayerGroup; /** * Returns true if the given layer is currently added to the group. @@ -1576,23 +1576,23 @@ declare module L { /** * Returns the layer with the given id. */ - getLayer(id: string): ILayer; + getLayer(id: string): T; /** * Returns an array of all the layers added to the group. */ - getLayers(): ILayer[]; + getLayers(): T[]; /** * Removes all the layers from the group. */ - clearLayers(): LayerGroup; + clearLayers(): LayerGroup; /** * Iterates over the layers of the group, optionally specifying context of * the iterator function. */ - eachLayer(fn: (layer: ILayer) => void, context?: any): LayerGroup; + eachLayer(fn: (layer: ILayer) => void, context?: any): LayerGroup; /** * Returns a GeoJSON representation of the layer group (GeoJSON FeatureCollection). @@ -2794,7 +2794,7 @@ declare module L { */ function multiPolygon(latlngs: LatLng[][], options?: PolylineOptions): MultiPolygon; - export class MultiPolygon extends FeatureGroup { + export class MultiPolygon extends FeatureGroup { /** * Instantiates a multi-polyline object given an array of latlngs arrays (one @@ -2829,7 +2829,7 @@ declare module L { */ function multiPolyline(latlngs: LatLng[][], options?: PolylineOptions): MultiPolyline; - export class MultiPolyline extends FeatureGroup { + export class MultiPolyline extends FeatureGroup { /** * Instantiates a multi-polyline object given an array of arrays of geographical @@ -3655,27 +3655,27 @@ declare module L { } } - export interface TileLayerFactory { + export interface TileLayerFactory { /** * Instantiates a tile layer object given a URL template and optionally an options * object. */ - (urlTemplate: string, options?: TileLayerOptions): TileLayer; + (urlTemplate: string, options?: TileLayerOptions): TileLayer; /** * Instantiates a WMS tile layer object given a base URL of the WMS service and * a WMS parameters/options object. */ - wms(baseUrl: string, options: WMSOptions): L.TileLayer.WMS; + wms(baseUrl: string, options: WMSOptions): L.TileLayer.WMS; /** * Instantiates a Canvas tile layer object given an options object (optionally). */ - canvas(options?: TileLayerOptions): L.TileLayer.Canvas; + canvas(options?: TileLayerOptions): L.TileLayer.Canvas; } - - export var tileLayer: TileLayerFactory; + + export var tileLayer: TileLayerFactory; } declare module L { From 2cc004f73a492e687c069e1d0e78d8748f34dcf8 Mon Sep 17 00:00:00 2001 From: CyberFoxHax Date: Thu, 29 May 2014 18:05:15 +0200 Subject: [PATCH 2/2] More generics Forgot T in some places --- leaflet/leaflet.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/leaflet/leaflet.d.ts b/leaflet/leaflet.d.ts index c3e5ce8c57..54f0fe4f09 100644 --- a/leaflet/leaflet.d.ts +++ b/leaflet/leaflet.d.ts @@ -1556,12 +1556,12 @@ declare module L { /** * Adds a given layer to the group. */ - addLayer(layer: ILayer): LayerGroup; + addLayer(layer: T): LayerGroup; /** * Removes a given layer from the group. */ - removeLayer(layer: ILayer): LayerGroup; + removeLayer(layer: T): LayerGroup; /** * Removes a given layer of the given id from the group. @@ -1571,7 +1571,7 @@ declare module L { /** * Returns true if the given layer is currently added to the group. */ - hasLayer(layer: ILayer): boolean; + hasLayer(layer: T): boolean; /** * Returns the layer with the given id. @@ -1592,7 +1592,7 @@ declare module L { * Iterates over the layers of the group, optionally specifying context of * the iterator function. */ - eachLayer(fn: (layer: ILayer) => void, context?: any): LayerGroup; + eachLayer(fn: (layer: T) => void, context?: any): LayerGroup; /** * Returns a GeoJSON representation of the layer group (GeoJSON FeatureCollection).