leaflet-geoman: Incorrect TS typings

Hi, I updated to the last version and got couple of new errors:

  1. setPathOptions should have second argument as optional in TS definition. Also newly added merge field is missing
  2. disableDraw accepts shape argument. It is optional, but it is still there. I guess the right option is to remove shape from the code, not from typings.
  3. I see that there are newly added typings for event handlers. For example, the layer is now L.Layer. Are you sure this is the best typings? Because now I cannot use setStyle or toGeoJSON functions without fighting TS

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@tirli do you mean like this, but before you didn’t have to typecast polygon?

import { PM, Polygon } from 'leaflet';
export type DrawStartEventHandler = (e: {
  shape: PM.SUPPORTED_SHAPES;
  workingLayer: L.Layer;
}) => void;

const a: DrawStartEventHandler = e => {
  const geo = e.workingLayer.toGeoJSON(); // does not work
  const geo2 = (e.workingLayer as Polygon).toGeoJSON(); // works
};

@Falke-Design is there a specific subset of the types that can be passed into the event handlers as workingLayer? Unless all of the types that layer can be set to have a toGeoJSON() method, you would have to typecast to access more type specific methods

PR for the changes: #915

One more addition I just found: rotateMode is missing in ToolbarOptions

Thanks for reporting, we will change 1 and 2.

@ryan-morris can you please answer point 3.