Thanks to visit codestin.com
Credit goes to github.com

Skip to content

types: extend LeafletEventHandlerFnMap with pm:* events#1659

Open
mvanhorn wants to merge 18 commits into
geoman-io:masterfrom
mvanhorn:types/extend-leaflet-event-handler-fn-map
Open

types: extend LeafletEventHandlerFnMap with pm:* events#1659
mvanhorn wants to merge 18 commits into
geoman-io:masterfrom
mvanhorn:types/extend-leaflet-event-handler-fn-map

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

Summary

Closes #1515.

The pm:* events are typed today via on / once / off overloads on the
Evented interface, which covers the imperative API:

map.on('pm:edit', (e) => { /* e is typed correctly */ });

But the keyed form -- used by react-leaflet's eventHandlers prop and any
other consumer that builds a record literal and passes it to on(eventMap) --
flows through LeafletEventHandlerFnMap, which has a fixed key set in
@types/leaflet (no string index signature). That meant:

<Polyline
  eventHandlers={{
    'pm:edit': (e) => { /* e is `any`, the key wasn't validated */ }
  }}
/>

neither type-checked the event name nor the handler payload, and react-leaflet
users had to ship a private leaflet.d.ts shim that mirrors the pm:* events.
The issue thread describes exactly this experience.

Implementation

Extends LeafletEventHandlerFnMap inside the existing
declare module 'leaflet' block with the same handler types already used
by the on / once / off overloads. No new handler types are introduced;
this is purely a record-form mirror of the imperative overloads.

pm:vertexadded carries two payload shapes today (PM.VertexAddedEventHandler
in draw mode, PM.VertexAddedEventHandler2 in edit mode) and the file already
declares two on overloads for it. The record entry is typed as the union of
both so the keyed form matches the existing imperative behavior exactly.

File Change
leaflet-geoman.d.ts Add LeafletEventHandlerFnMap augmentation, +129 lines

No source changes -- this is a .d.ts-only PR.

Verification

npm run typecheck       # tsc --noEmit, clean
npm run lint:check      # oxlint + oxfmt, clean

Quick sanity check that the augmentation flows into a record literal:

import * as L from 'leaflet';
import './leaflet-geoman.d.ts';

const handlers: L.LeafletEventHandlerFnMap = {
  click: (e) => { /* leaflet built-in */ },
  'pm:edit': (e) => {
    const layer: L.Layer = e.layer;        // typed
    const shape: PM.SUPPORTED_SHAPES = e.shape;
  },
  'pm:create': (e) => { console.log(e.shape); },
};

tsc --noEmit accepts this with the patch applied; without it, 'pm:edit'
would error as an unknown property of LeafletEventHandlerFnMap and e
would fall back to any.

Notes

  • The existing on / once / off overloads are unchanged. Anything that
    worked before still works -- this is purely additive type information.
  • The augmentation is in the same declare module 'leaflet' block that
    already extends Evented, Map, Path, etc., so consumers don't need
    any extra imports.
  • I did not extend the underlying LeafletEventHandlerFn shape or change
    any payload types -- the maintainer comment ("we are happy to add
    solutions but we are not TypeScript developers") suggested keeping the
    scope tight, so this just mirrors what's already there.

dependabot Bot and others added 18 commits May 11, 2026 16:36
…o#1631)

Bumps the dev-dependencies group with 2 updates: [oxlint](https://github.com/oxc-project/oxc/tree/HEAD/npm/oxlint) and [prosthetic-hand](https://github.com/IvanSanchez/prosthetic-hand).


Updates `oxlint` from 1.16.0 to 1.43.0
- [Release notes](https://github.com/oxc-project/oxc/releases)
- [Changelog](https://github.com/oxc-project/oxc/blob/main/npm/oxlint/CHANGELOG.md)
- [Commits](https://github.com/oxc-project/oxc/commits/oxlint_v1.43.0/npm/oxlint)

Updates `prosthetic-hand` from 1.3.1 to 1.4.0
- [Changelog](https://github.com/Leaflet/prosthetic-hand/blob/main/CHANGELOG.md)
- [Commits](https://github.com/IvanSanchez/prosthetic-hand/commits)

---
updated-dependencies:
- dependency-name: oxlint
  dependency-version: 1.43.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: prosthetic-hand
  dependency-version: 1.4.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…eoman-io#1634)

Bumps the production-dependencies group with 4 updates: [@turf/boolean-contains](https://github.com/Turfjs/turf), [@turf/kinks](https://github.com/Turfjs/turf), [@turf/line-intersect](https://github.com/Turfjs/turf) and [@turf/line-split](https://github.com/Turfjs/turf).


Updates `@turf/boolean-contains` from 7.3.3 to 7.3.4
- [Release notes](https://github.com/Turfjs/turf/releases)
- [Changelog](https://github.com/Turfjs/turf/blob/master/CHANGELOG.md)
- [Commits](Turfjs/turf@v7.3.3...v7.3.4)

Updates `@turf/kinks` from 7.3.3 to 7.3.4
- [Release notes](https://github.com/Turfjs/turf/releases)
- [Changelog](https://github.com/Turfjs/turf/blob/master/CHANGELOG.md)
- [Commits](Turfjs/turf@v7.3.3...v7.3.4)

Updates `@turf/line-intersect` from 7.3.3 to 7.3.4
- [Release notes](https://github.com/Turfjs/turf/releases)
- [Changelog](https://github.com/Turfjs/turf/blob/master/CHANGELOG.md)
- [Commits](Turfjs/turf@v7.3.3...v7.3.4)

Updates `@turf/line-split` from 7.3.3 to 7.3.4
- [Release notes](https://github.com/Turfjs/turf/releases)
- [Changelog](https://github.com/Turfjs/turf/blob/master/CHANGELOG.md)
- [Commits](Turfjs/turf@v7.3.3...v7.3.4)

---
updated-dependencies:
- dependency-name: "@turf/boolean-contains"
  dependency-version: 7.3.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: production-dependencies
- dependency-name: "@turf/kinks"
  dependency-version: 7.3.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: production-dependencies
- dependency-name: "@turf/line-intersect"
  dependency-version: 7.3.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: production-dependencies
- dependency-name: "@turf/line-split"
  dependency-version: 7.3.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: production-dependencies
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…o#1633)

Bumps the dev-dependencies group with 2 updates: [cypress](https://github.com/cypress-io/cypress) and [esbuild](https://github.com/evanw/esbuild).


Updates `cypress` from 15.9.0 to 15.10.0
- [Release notes](https://github.com/cypress-io/cypress/releases)
- [Changelog](https://github.com/cypress-io/cypress/blob/develop/CHANGELOG.md)
- [Commits](cypress-io/cypress@v15.9.0...v15.10.0)

Updates `esbuild` from 0.27.2 to 0.27.3
- [Release notes](https://github.com/evanw/esbuild/releases)
- [Changelog](https://github.com/evanw/esbuild/blob/main/CHANGELOG.md)
- [Commits](evanw/esbuild@v0.27.2...v0.27.3)

---
updated-dependencies:
- dependency-name: cypress
  dependency-version: 15.10.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: esbuild
  dependency-version: 0.27.3
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: dev-dependencies
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [qs](https://github.com/ljharb/qs) from 6.14.1 to 6.14.2.
- [Changelog](https://github.com/ljharb/qs/blob/main/CHANGELOG.md)
- [Commits](ljharb/qs@v6.14.1...v6.14.2)

---
updated-dependencies:
- dependency-name: qs
  dependency-version: 6.14.2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…o#1636)

Bumps the dev-dependencies group with 2 updates: [oxlint](https://github.com/oxc-project/oxc/tree/HEAD/npm/oxlint) and [oxfmt](https://github.com/oxc-project/oxc/tree/HEAD/npm/oxfmt).


Updates `oxlint` from 1.43.0 to 1.47.0
- [Release notes](https://github.com/oxc-project/oxc/releases)
- [Changelog](https://github.com/oxc-project/oxc/blob/main/npm/oxlint/CHANGELOG.md)
- [Commits](https://github.com/oxc-project/oxc/commits/oxlint_v1.47.0/npm/oxlint)

Updates `oxfmt` from 0.28.0 to 0.32.0
- [Release notes](https://github.com/oxc-project/oxc/releases)
- [Changelog](https://github.com/oxc-project/oxc/blob/main/npm/oxfmt/CHANGELOG.md)
- [Commits](https://github.com/oxc-project/oxc/commits/oxfmt_v0.32.0/npm/oxfmt)

---
updated-dependencies:
- dependency-name: oxlint
  dependency-version: 1.47.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: oxfmt
  dependency-version: 0.32.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…1637)

Bumps [systeminformation](https://github.com/sebhildebrandt/systeminformation) from 5.30.7 to 5.31.1.
- [Release notes](https://github.com/sebhildebrandt/systeminformation/releases)
- [Changelog](https://github.com/sebhildebrandt/systeminformation/blob/master/CHANGELOG.md)
- [Commits](sebhildebrandt/systeminformation@v5.30.7...v5.31.1)

---
updated-dependencies:
- dependency-name: systeminformation
  dependency-version: 5.31.1
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [rollup](https://github.com/rollup/rollup) from 4.57.1 to 4.59.0.
- [Release notes](https://github.com/rollup/rollup/releases)
- [Changelog](https://github.com/rollup/rollup/blob/master/CHANGELOG.md)
- [Commits](rollup/rollup@v4.57.1...v4.59.0)

---
updated-dependencies:
- dependency-name: rollup
  dependency-version: 4.59.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps  and [picomatch](https://github.com/micromatch/picomatch). These dependencies needed to be updated together.

Updates `picomatch` from 4.0.3 to 4.0.4
- [Release notes](https://github.com/micromatch/picomatch/releases)
- [Changelog](https://github.com/micromatch/picomatch/blob/master/CHANGELOG.md)
- [Commits](micromatch/picomatch@4.0.3...4.0.4)

Updates `picomatch` from 2.3.1 to 2.3.2
- [Release notes](https://github.com/micromatch/picomatch/releases)
- [Changelog](https://github.com/micromatch/picomatch/blob/master/CHANGELOG.md)
- [Commits](micromatch/picomatch@4.0.3...4.0.4)

---
updated-dependencies:
- dependency-name: picomatch
  dependency-version: 4.0.4
  dependency-type: indirect
- dependency-name: picomatch
  dependency-version: 2.3.2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.23 to 4.18.1.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](lodash/lodash@4.17.23...4.18.1)

---
updated-dependencies:
- dependency-name: lodash
  dependency-version: 4.18.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…eoman-io#1646)

All PM event handlers now include `source` and an index signature for
custom payload properties via BaseEventPayload intersection, matching
the runtime behavior in Events.js where __fire() merges { source } and
customPayload into every event.

Fixes geoman-io#1111

Co-authored-by: Matt Van Horn <[email protected]>
…7 updates (geoman-io#1640)

Bumps the dev-dependencies group with 6 updates in the / directory:

| Package | From | To |
| --- | --- | --- |
| [@vitest/coverage-v8](https://github.com/vitest-dev/vitest/tree/HEAD/packages/coverage-v8) | `4.0.18` | `4.1.0` |
| [cypress](https://github.com/cypress-io/cypress) | `15.10.0` | `15.12.0` |
| [esbuild](https://github.com/evanw/esbuild) | `0.27.3` | `0.27.4` |
| [oxlint](https://github.com/oxc-project/oxc/tree/HEAD/npm/oxlint) | `1.47.0` | `1.56.0` |
| [oxfmt](https://github.com/oxc-project/oxc/tree/HEAD/npm/oxfmt) | `0.32.0` | `0.41.0` |
| [lint-staged](https://github.com/lint-staged/lint-staged) | `16.2.7` | `16.4.0` |



Updates `@vitest/coverage-v8` from 4.0.18 to 4.1.0
- [Release notes](https://github.com/vitest-dev/vitest/releases)
- [Commits](https://github.com/vitest-dev/vitest/commits/v4.1.0/packages/coverage-v8)

Updates `cypress` from 15.10.0 to 15.12.0
- [Release notes](https://github.com/cypress-io/cypress/releases)
- [Changelog](https://github.com/cypress-io/cypress/blob/develop/CHANGELOG.md)
- [Commits](cypress-io/cypress@v15.10.0...v15.12.0)

Updates `esbuild` from 0.27.3 to 0.27.4
- [Release notes](https://github.com/evanw/esbuild/releases)
- [Changelog](https://github.com/evanw/esbuild/blob/main/CHANGELOG.md)
- [Commits](evanw/esbuild@v0.27.3...v0.27.4)

Updates `oxlint` from 1.47.0 to 1.56.0
- [Release notes](https://github.com/oxc-project/oxc/releases)
- [Changelog](https://github.com/oxc-project/oxc/blob/main/npm/oxlint/CHANGELOG.md)
- [Commits](https://github.com/oxc-project/oxc/commits/oxlint_v1.56.0/npm/oxlint)

Updates `oxfmt` from 0.32.0 to 0.41.0
- [Release notes](https://github.com/oxc-project/oxc/releases)
- [Changelog](https://github.com/oxc-project/oxc/blob/main/npm/oxfmt/CHANGELOG.md)
- [Commits](https://github.com/oxc-project/oxc/commits/oxfmt_v0.41.0/npm/oxfmt)

Updates `lint-staged` from 16.2.7 to 16.4.0
- [Release notes](https://github.com/lint-staged/lint-staged/releases)
- [Changelog](https://github.com/lint-staged/lint-staged/blob/main/CHANGELOG.md)
- [Commits](lint-staged/lint-staged@v16.2.7...v16.4.0)

Updates `vitest` from 4.0.18 to 4.1.0
- [Release notes](https://github.com/vitest-dev/vitest/releases)
- [Commits](https://github.com/vitest-dev/vitest/commits/v4.1.0/packages/vitest)

---
updated-dependencies:
- dependency-name: "@vitest/coverage-v8"
  dependency-version: 4.1.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: cypress
  dependency-version: 15.12.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: esbuild
  dependency-version: 0.27.4
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: dev-dependencies
- dependency-name: oxlint
  dependency-version: 1.56.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: oxfmt
  dependency-version: 0.41.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: lint-staged
  dependency-version: 16.4.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
- dependency-name: vitest
  dependency-version: 4.1.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: dev-dependencies
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
The pm:* events are typed via 'on' / 'once' / 'off' overloads on
the Evented interface, which covers the imperative API:

  map.on('pm:edit', (e) => /* e typed correctly */)

But the keyed form (used by react-leaflet's eventHandlers prop and
any other consumer that builds a record literal and passes it to
on(eventMap)) goes through LeafletEventHandlerFnMap, which has a
fixed key set in @types/leaflet -- no string index signature.
That meant <Polyline eventHandlers={{ 'pm:edit': handler }} />
neither type-checked the event name nor the handler payload, and
react-leaflet users had to ship private leaflet.d.ts shims.

This extends the LeafletEventHandlerFnMap interface inside the
existing 'declare module "leaflet"' block with the same handler
types already used by the on/once/off overloads. pm:vertexadded
keeps both shapes (draw-mode VertexAddedEventHandler and
edit-mode VertexAddedEventHandler2) as a union, mirroring the two
existing on() overloads.

Closes geoman-io#1515.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@Falke-Design Falke-Design force-pushed the types/extend-leaflet-event-handler-fn-map branch from a6c2d12 to 884e8e8 Compare May 11, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants