From 9b14df292e2f34a136da02efda2bc5daab3690f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20S=C3=A1nchez?= Date: Fri, 17 Feb 2017 08:24:43 -0600 Subject: [PATCH] Fixed Icon type hierarchy --- leaflet/index.d.ts | 35 +++++++++++++++++++++++------------ leaflet/leaflet-tests.ts | 7 +++++++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/leaflet/index.d.ts b/leaflet/index.d.ts index 5ca606811a..717e589877 100644 --- a/leaflet/index.d.ts +++ b/leaflet/index.d.ts @@ -1405,8 +1405,8 @@ declare namespace L { */ export function map(element: string | HTMLElement, options?: MapOptions): Map; - export interface IconOptions extends LayerOptions { - iconUrl: string; + interface BaseIconOptions extends LayerOptions { + iconUrl?: string; iconRetinaUrl?: string; iconSize?: PointExpression; iconAnchor?: PointExpression; @@ -1418,25 +1418,38 @@ declare namespace L { className?: string; } - class InternalIcon extends Layer { - constructor(options: IconOptions); - createIcon(oldIcon?: HTMLElement): HTMLElement; + export interface IconOptions extends BaseIconOptions { + iconUrl: string; } - export class Icon extends InternalIcon { + // This class does not exist in reality, it's just a way to provide + // options of more specific types in the sub classes + class BaseIcon extends Layer { + createIcon(oldIcon?: HTMLElement): HTMLElement; createShadow(oldIcon?: HTMLElement): HTMLElement; + options: BaseIconOptions; + } + + export class Icon extends BaseIcon { + constructor(options: IconOptions); options: IconOptions; } export namespace Icon { - export class Default extends InternalIcon { - imagePath: string; + export interface DefaultIconOptions extends BaseIconOptions { + imagePath?: string; + } + + export class Default extends BaseIcon { + static imagePath?: string; + constructor(options?: DefaultIconOptions); + options: DefaultIconOptions; } } export function icon(options: IconOptions): Icon; - export interface DivIconOptions extends LayerOptions { + export interface DivIconOptions extends BaseIconOptions { html?: string; bgPos?: PointExpression; iconSize?: PointExpression; @@ -1445,7 +1458,7 @@ declare namespace L { className?: string; } - export class DivIcon extends InternalIcon { + export class DivIcon extends BaseIcon { constructor(options?: DivIconOptions); options: DivIconOptions; } @@ -1463,8 +1476,6 @@ declare namespace L { opacity?: number; riseOnHover?: boolean; riseOffset?: number; - - options?: DivIconOptions; } export class Marker extends Layer { diff --git a/leaflet/leaflet-tests.ts b/leaflet/leaflet-tests.ts index 8d9b91e37b..bce7afdab6 100644 --- a/leaflet/leaflet-tests.ts +++ b/leaflet/leaflet-tests.ts @@ -404,22 +404,29 @@ class MyMarker extends L.Marker { super([12, 13]); } } + class MyLayer extends L.Layer { constructor() { super(); } } + class MyIcon extends L.Icon { constructor() { super({iconUrl: 'icon.png'}); } } + class MyDivIcon extends L.DivIcon { constructor() { super(); } } +const divIcon = L.divIcon({html: ''}); +let defaultIcon = new L.Icon.Default(); +defaultIcon = new L.Icon.Default({imagePath: 'apath'}); + let myControlClass = L.Control.extend({}); let myControl = new myControlClass();