geoman-io/leaflet-geoman

typescript typings show all events on Map and Layer

Aperta

#893 aperta il 10 mag 2021

 (1 commento) (1 reazione) (0 assegnatari)JavaScript (404 fork)batch import
help wantedtypescript

Metriche repository

Star
 (1933 stelle)
Metriche merge PR
 (Merge medio 9g 6h) (5 PR mergiate in 30 g)

Descrizione

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

Guida contributor