Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typescript typings show all events on Map and Layer #893

Open
ryan-morris opened this issue May 10, 2021 · 1 comment
Open

typescript typings show all events on Map and Layer #893

ryan-morris opened this issue May 10, 2021 · 1 comment

Comments

@ryan-morris
Copy link
Contributor

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

@Falke-Design
Copy link
Collaborator

@ryan-morris can use please look into: Leaflet/Leaflet#7729 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants