geoman-io/leaflet-geoman

typescript typings show all events on Map and Layer

Open

#893 建立於 2021年5月10日

在 GitHub 查看
 (1 留言) (1 反應) (0 負責人)JavaScript (1,933 star) (404 fork)batch import
help wantedtypescript

描述

PR #881 adds typings for the various events. The problem is that since they are registered on Evented from @types/leaflet they all show up when doing map.on() and layer.on() even though some of the events are either map or layer only.

Trying to put the events on the Map or Layer from @types/leaflet like:

    /**
     * Extends built in leaflet map.
     */
    interface Map {
        pm: PM.PMMap;

        on(type: 'pm:globaldrawmodetoggled', fn: (event: { enabled: boolean, shape: PM.SUPPORTED_SHAPES, map: L.Map }) => void, context?: any): L.Evented;
    }

results in the following error:

Interface 'Map' incorrectly extends interface 'Evented'.
  Types of property 'on' are incompatible.
    Type '(type: "pm:globaldrawmodetoggled", fn: (event: { enabled: boolean; shape: string; map: Map; }) => void, context?: any) => Evented' is not assignable to type '{ (type: string, fn: LeafletEventHandlerFn, context?: any): this; (type: "baselayerchange" | "overlayadd" | "overlayremove", fn: LayersControlEventHandlerFn, context?: any): this; (type: "layeradd" | "layerremove", fn: LayerEventHandlerFn, context?: any): this; (type: "zoomlevelschange" | ... 18 more ... | "predrag"...'.
      Types of parameters 'fn' and 'fn' are incompatible.
        Types of parameters 'event' and 'event' are incompatible.
          Type '{ enabled: boolean; shape: string; map: Map; }' is missing the following properties from type 'LeafletEvent': type, target, sourceTarget, propagatedFrom, layerts(2430)

We need to find a way to register the events for just Map and just Layer

貢獻者指南